android获取图片背景色,Android:使用选择器设置图像视图的背景颜色

我正在设置图像视图的背景颜色.

android:id="@+id/my_image"

android:src="@drawable/my_icon"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_weight="1"

android:clickable="true"

android:layout_alignParentLeft="true"

android:background="@drawable/selector_image_view" />

我正在使用以下选择器.

但是,如果我尝试使用选择器运行时异常,它会崩溃.我究竟做错了什么?

我的logcat

E/AndroidRuntime( 4196): FATAL EXCEPTION: main

E/AndroidRuntime( 4196): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.X.XCamera/com.X.XCamera.XCameraActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class

E/AndroidRuntime( 4196): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)

E/AndroidRuntime( 4196): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

E/AndroidRuntime( 4196): at android.app.ActivityThread.access$2300(ActivityThread.java:125)

E/AndroidRuntime( 4196): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)

E/AndroidRuntime( 4196): at android.os.Handler.dispatchMessage(Handler.java:99)

E/AndroidRuntime( 4196): at android.os.Looper.loop(Looper.java:123)

E/AndroidRuntime( 4196): at android.app.ActivityThread.main(ActivityThread.java:4627)

E/AndroidRuntime( 4196): at java.lang.reflect.Method.invokeNative(Native Method)

E/AndroidRuntime( 4196): at java.lang.reflect.Method.invoke(Method.java:521)

E/AndroidRuntime( 4196): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)

E/AndroidRuntime( 4196): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

E/AndroidRuntime( 4196): at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime( 4196): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class

E/AndroidRuntime( 4196): at android.view.LayoutInflater.createView(LayoutInflater.java:513)

E/AndroidRuntime( 4196): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)

E/AndroidRuntime( 4196): at com.X.XCamera.Settings.(Settings.java:52)

E/AndroidRuntime( 4196): at com.X.XCamera.XCameraActivity.onCreate(XCameraActivity.java:92)

E/AndroidRuntime( 4196): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

E/AndroidRuntime( 4196): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

E/AndroidRuntime( 4196): ... 11 more

E/AndroidRuntime( 4196): Caused by: java.lang.reflect.InvocationTargetException

E/AndroidRuntime( 4196): at android.widget.ImageView.(ImageView.java:108)

E/AndroidRuntime( 4196): at java.lang.reflect.Constructor.constructNative(Native Method)

E/AndroidRuntime( 4196): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)

E/AndroidRuntime( 4196): at android.view.LayoutInflater.createView(LayoutInflater.java:500)

E/AndroidRuntime( 4196): ... 22 more

E/AndroidRuntime( 4196): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/selector_image_view.xml from drawable resource ID #0x7f02000e

E/AndroidRuntime( 4196): at android.content.res.Resources.loadDrawable(Resources.java:1697)

E/AndroidRuntime( 4196): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)

E/AndroidRuntime( 4196): at android.view.View.(View.java:2045)

E/AndroidRuntime( 4196): at android.widget.ImageView.(ImageView.java:112)

E/AndroidRuntime( 4196): ... 26 more

E/AndroidRuntime( 4196): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: tag requires a 'drawable' attribute or child tag defining a drawable

E/AndroidRuntime( 4196): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:167)

E/AndroidRuntime( 4196): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)

E/AndroidRuntime( 4196): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)

E/AndroidRuntime( 4196): at android.content.res.Resources.loadDrawable(Resources.java:1694)

E/AndroidRuntime( 4196): ... 29 more

W/ActivityManager( 1707): Force finishing activity com.X.XCamera/.XCameraActivity

I/IMGSRV ( 1707): gralloc.c:803: gralloc_device_alloc: Allocated a new surface:

I/IMGSRV ( 1707): width -> 800

I/IMGSRV ( 1707): height -> 382

I/IMGSRV ( 1707): format -> 1 (HAL_PIXEL_FORMAT_RGBA_8888)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>