本文介绍了selectableItemBackground应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使使用的ImageButton的android:背景=ATTR / selectableItemBackground?
,但我的应用程序崩溃。我只是按照此这question.任何想法?
感谢您的帮助。
activity.xml
<的ImageButton
机器人:ID =@ + ID /注册 机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT 机器人:layout_alignLeft =@ + ID /登入
机器人:layout_alignParentBottom =真
机器人:layout_marginBottom =80dp 机器人:ATTR / selectableItemBackground背景= 机器人:SRC =@绘制/ sign_up
机器人:contentDescription =@字符串/ button_sign_up
/>
登录猫
18 05-31:50:24.077:W / dalvikvm(28619):主题ID = 1:螺纹未捕获的异常退出(组= 0x41d0b2a0)
05-31 18:50:24.082:E / AndroidRuntime(28619):致命异常:主要
05-31 18:50:24.082:E / AndroidRuntime(28619):了java.lang.RuntimeException:无法启动活动ComponentInfo {yai.properti.tujuh.tujuh.tujuh / yai.properti.tujuh.tujuh.tujuh.WelcomeActivity} :android.view.InflateException:二进制XML文件行#9:错误充气类android.widget.ImageButton
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread.access $ 700(ActivityThread.java:140)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1237)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.os.Handler.dispatchMessage(Handler.java:99)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.os.Looper.loop(Looper.java:137)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread.main(ActivityThread.java:4921)
05-31 18:50:24.082:E / AndroidRuntime(28619):在java.lang.reflect.Method.invokeNative(本机方法)
05-31 18:50:24.082:E / AndroidRuntime(28619):在java.lang.reflect.Method.invoke(Method.java:511)
05-31 18:50:24.082:E / AndroidRuntime(28619):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-31 18:50:24.082:E / AndroidRuntime(28619):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-31 18:50:24.082:E / AndroidRuntime(28619):在dalvik.system.NativeStart.main(本机方法)
05-31 18:50:24.082:E / AndroidRuntime(28619):android.view.InflateException:二进制XML文件行#9:错误充气类android.widget.ImageButton产生的原因
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-31 18:50:24.082:E / AndroidRuntime(28619):在com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-31 18:50:24.082:E / AndroidRuntime(28619):在com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.Activity.setContentView(Activity.java:1924)
05-31 18:50:24.082:E / AndroidRuntime(28619):在yai.properti.tujuh.tujuh.tujuh.WelcomeActivity.onCreate(WelcomeActivity.java:19)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.Activity.performCreate(Activity.java:5188)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-31 18:50:24.082:E / AndroidRuntime(28619):... 11个
05-31 18:50:24.082:E / AndroidRuntime(28619):由:java.lang.reflect.InvocationTargetException
05-31 18:50:24.082:E / AndroidRuntime(28619):在java.lang.reflect.Constructor.constructNative(本机方法)
05-31 18:50:24.082:E / AndroidRuntime(28619):在java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-31 18:50:24.082:E / AndroidRuntime(28619):24 ...更多
05-31 18:50:24.082:E / AndroidRuntime(28619):$ android.content.res.Resources NotFoundException:由造成资源不是绘制对象(彩色或路径):{的TypedValue T = 0X2 / D = 0x7f010015一个= -1}
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.content.res.Resources.loadDrawable(Resources.java:1925)
05-31 18:50:24.082:E / AndroidRuntime(28619):在android.content.res.TypedArray.getDrawable(TypedArray.java:601)
。05-31 18:50:24.082:E / AndroidRuntime(28619):在android.view.View<&初始化GT;(View.java:3449)
。05-31 18:50:24.082:E / AndroidRuntime(28619):在android.widget.ImageView<&初始化GT;(ImageView.java:114)
。05-31 18:50:24.082:E / AndroidRuntime(28619):在android.widget.ImageButton<&初始化GT;(ImageButton.java:87)
。05-31 18:50:24.082:E / AndroidRuntime(28619):在android.widget.ImageButton<&初始化GT;(ImageButton.java:83)
05-31 18:50:24.082:E / AndroidRuntime(28619):... 27个
解决方案
要使它工作,你应该在你的应用程序或活动使用AppCompact基本主题。像下面这样:
<样式名称=AppBaseTheme父=Theme.AppCompat.Light.NoActionBar>
< /风格>
i'm trying to make ImageButton usingandroid:background="?attr/selectableItemBackground"
but my app crashed. I just following this answer and this question. Any idea?
Thanks for your help.
activity.xml
<ImageButton
android:id="@+id/signUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/signIn"
android:layout_alignParentBottom="true"
android:layout_marginBottom="80dp"
android:background="?attr/selectableItemBackground"
android:src="@drawable/sign_up"
android:contentDescription="@string/button_sign_up"
/>
Log Cat
05-31 18:50:24.077: W/dalvikvm(28619): threadid=1: thread exiting with uncaught exception (group=0x41d0b2a0)
05-31 18:50:24.082: E/AndroidRuntime(28619): FATAL EXCEPTION: main
05-31 18:50:24.082: E/AndroidRuntime(28619): java.lang.RuntimeException: Unable to start activity ComponentInfo{yai.properti.tujuh.tujuh.tujuh/yai.properti.tujuh.tujuh.tujuh.WelcomeActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageButton
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.access$700(ActivityThread.java:140)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.os.Handler.dispatchMessage(Handler.java:99)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.os.Looper.loop(Looper.java:137)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.main(ActivityThread.java:4921)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Method.invokeNative(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Method.invoke(Method.java:511)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
05-31 18:50:24.082: E/AndroidRuntime(28619): at dalvik.system.NativeStart.main(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageButton
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-31 18:50:24.082: E/AndroidRuntime(28619): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:316)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Activity.setContentView(Activity.java:1924)
05-31 18:50:24.082: E/AndroidRuntime(28619): at yai.properti.tujuh.tujuh.tujuh.WelcomeActivity.onCreate(WelcomeActivity.java:19)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Activity.performCreate(Activity.java:5188)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 11 more
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: java.lang.reflect.InvocationTargetException
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Constructor.constructNative(Native Method)
05-31 18:50:24.082: E/AndroidRuntime(28619): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 24 more
05-31 18:50:24.082: E/AndroidRuntime(28619): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x7f010015 a=-1}
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.content.res.Resources.loadDrawable(Resources.java:1925)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.view.View.<init>(View.java:3449)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageView.<init>(ImageView.java:114)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageButton.<init>(ImageButton.java:87)
05-31 18:50:24.082: E/AndroidRuntime(28619): at android.widget.ImageButton.<init>(ImageButton.java:83)
05-31 18:50:24.082: E/AndroidRuntime(28619): ... 27 more
解决方案
To make it work you should use AppCompact base theme in your App or Activity. Like following:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
这篇关于selectableItemBackground应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!