LayoutInflater.Factory 妙用
来源:互联网 发布:淘宝运营推广区别 编辑:程序博客网 时间:2024/06/05 02:31
LayoutInflater.Factory 可以调试 布局,你把下面的代码放到
onCreate里面,然后再里面的下面的onCreateView里面加上断点,然后你就可以知道所有的view构造,所有的view的名字,不管是自定义还是系统的。
感觉挺不错的。
protected void setMenuBackGround() { LayoutInflater layoutInflater = getLayoutInflater(); final LayoutInflater.Factory existingFactory = layoutInflater.getFactory();// use introspection to allow a new Factory to be set try { Field field = LayoutInflater.class.getDeclaredField("mFactorySet"); field.setAccessible(true); field.setBoolean(layoutInflater, false); getLayoutInflater().setFactory(new LayoutInflater.Factory() { @Override public View onCreateView(String name, final Context context, AttributeSet attrs) { if (name .equalsIgnoreCase("android.support.v7.internal.view.menu.ListMenuItemView")) { try { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.createView(name, null, attrs); new Handler().post(new Runnable() { public void run() { ViewParent parent = view.getParent(); ((ViewGroup) parent).setBackgroundResource(R.color.test);// view.setBackgroundResource(R.color.test); } }); return view; } catch (InflateException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } // do whatever you want with the null or non-null view // such as expanding 'IconMenuItemView' and changing its style // or anything else... // and return the view return null; } }); } catch (NoSuchFieldException e) { // ... } catch (IllegalArgumentException e) { // ... } catch (IllegalAccessException e) { // ... } }
然后这个类也很强大,可以做很多事情,向下兼容。等等,替换东西等等。
0 0
- LayoutInflater.Factory的妙用
- LayoutInflater.Factory 妙用
- 自定义LayoutInflater.Factory
- 遇见LayoutInflater&Factory
- LayoutInflater Factory使用基础与进阶
- 基于spring factory-bean的妙用
- A factory has already been set on this LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- LayoutInflater
- MYSQL
- 链表基本操作
- 继续(3n+1)猜想 (25)
- 关于深拷贝和浅拷贝
- AndroidManifest.xml权限设置
- LayoutInflater.Factory 妙用
- java 多态
- Android总结篇系列:Android Intent
- 借助goole浏览器调整页面css样式
- MStar2256A升级FW失败后TP无功能
- ENVI下植被覆盖度的遥感估算
- Longest Repeating Character Replacement
- 总结
- Apriori算法