fengshenzhu / reskin1 Goto Github PK
View Code? Open in Web Editor NEWAndroid换肤库
Home Page: https://fengshenzhu.github.io/library-reskin/
Android换肤库
Home Page: https://fengshenzhu.github.io/library-reskin/
现在所有属于一个Activity的View都会添加到一份列表里,自定义View可以通过onAttachedToWindow()``onDetachedFromWindow()
添加/移除,Fragment是否也需要通过onAttach()``onDetach()
做次操作?
Caused by: android.view.InflateException: Binary XML file line #8: Class is not a View android.support.v4.app.Fragment
at android.view.LayoutInflater.createView(LayoutInflater.java:636)
at skin.lib.SkinLayoutInflaterFactory.createView(SkinLayoutInflaterFactory.java:132)
at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:94)
获取LayoutInflater的方式:
LayoutInflater.from(activity)
LayoutInflater.from(activity.getApplicationContext())
LayoutInflater.from(activity.getBaseContext())
Activity.getLayoutInflater()
Fragment.getLayoutInflater(savedInstanceState)
Fragment.onCreateView(LayoutInflater inflater, ...)
View.inflater(context...)
其中,只有1.1和2.1获取的是同一个LayoutInflater对象,其它都不是同一个对象。
Fragment3.1和3.2LayoutInflater对象的Factory是Merge之后的,其中一个对象与1.1的Factory相同。(更详细见LayoutInflater.FactoryMerge)
无论是系统style还是自定义style,都会报错:
java.lang.NumberFormatException: Invalid int: "xxxxxx"
at java.lang.Integer.invalidInt(Integer.java:138)
at java.lang.Integer.parse(Integer.java:410)
at java.lang.Integer.parseInt(Integer.java:367)
at java.lang.Integer.parseInt(Integer.java:334)
at skin.lib.SkinLayoutInflaterFactory.addSkinViewIfNecessary(SkinLayoutInflaterFactory.java:153)
at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:108)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
... 46 more
系统:
java.lang.NumberFormatException: Invalid int: "android:style/Widget.ProgressBar.Large"
自定义:
java.lang.NumberFormatException: Invalid int: "style="@style/roomRatingBar"
自定义View的attach和detach操作可通过View#addOnAttachStateChangeListener()简化成一步。xml里由库添加lisenter,手动new View后需手动添加lisenter
换肤资源文件可能未被直接引用,默认打包压缩资源时可能被压缩掉,造成Resource$NotFoundException
。
解决方案:使用tools:keep
,参见:
http://tools.android.com/tech-docs/new-build-system/resource-shrinking
Fragment onCreateView()使用参数中inflater
布局
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_a, container, false);
}
布局fragment xml时报错:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
at android.view.ViewConfiguration.get(ViewConfiguration.java:364)
at android.view.View.<init>(View.java:3794)
at android.view.View.<init>(View.java:3898)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.widget.LinearLayout.<init>(LinearLayout.java:203)
at android.widget.LinearLayout.<init>(LinearLayout.java:199)
at android.widget.LinearLayout.<init>(LinearLayout.java:195)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at skin.lib.SkinLayoutInflaterFactory.createView(SkinLayoutInflaterFactory.java:126)
at skin.lib.SkinLayoutInflaterFactory.onCreateView(SkinLayoutInflaterFactory.java:99)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:190)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at skin.demo.FragmentA.onCreateView(FragmentA.java:31)
使用getActivity().getLayoutInflater()不会出错。
非默认主题下每次添加一个Fragment都会刷新整个Activity的View列表
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.