我有这样的XML drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<bitmap android:gravity="center" android:src="?attr/img_chat_sendbar_more"></bitmap>
</item>
<item android:state_pressed="true">
<layer-list>
<item>
<shape>
<solid android:color="?attr/color_transparent_icon"></solid>
</shape>
</item>
<item>
<bitmap android:gravity="center" android:src="?attr/img_chat_sendbar_more"></bitmap>
</item>
</layer-list>
</item>
</selector>
在这个drawable我使用主题属性&#39; img_chat_sendbar_more&#39;,它定义如下:
<attr name="img_chat_sendbar_more" format="reference"/>
并在主题中使用:
<item name="img_chat_sendbar_more">@mipmap/chat_sendbar_more</item>
但是,当app运行时,它会崩溃并输出“错误充气类”#39;错误 像:
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/chat_sendbar_ok.xml from drawable resource ID #0x7f020045
at android.content.res.Resources.loadDrawable(Resources.java:2091)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:3364)
at android.widget.TextView.<init>(TextView.java:619)
at android.widget.Button.<init>(Button.java:107)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:63)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:59)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at pj.mobile.app.wewe.view.communication.Fragment_Chat.onCreateView(Fragment_Chat.java:106)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1965)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1078)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1259)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1624)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5136)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4: <bitmap> requires a valid src attribute
at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:490)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:183)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:901)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:837)
at android.content.res.Resources.loadDrawable(Resources.java:2087)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.<init>(View.java:3364)
at android.widget.TextView.<init>(TextView.java:619)
at android.widget.Button.<init>(Button.java:107)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:63)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:59)
at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at pj.mobile.app.wewe.view.communication.Fragment_Chat.onCreateView(Fragment_Chat.java:106)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1965)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1078)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1259)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1624)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5136)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
然而,当我直接使用drawable资源而不是主题属性时,它运行OK.So我有一个问题,XML drawables支持主题属性吗?
答案 0 :(得分:0)
styles.xml或&#34;主题功能&#34;用于自定义Android小部件/视图的外观,例如:TextView
,EditView
,RecyclerView
等。
另一方面,可绘制XML是一个可绘制的资源(就像一个png)而不是一个视图。
换句话说:
不,drawable xml不能像其他一样使用styles.xml主题 android视图,因为它是一种资源。