android - Effect for Button after changing backgroundcolor -


i changed background color button , there no click effect more.

to effect back, way give button different background colors.

i tried this:

in drawable-mdpi, created button_bg.xml.

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">     <item android:state_pressed="true"           android:color="#ffff0000"/> <!-- pressed -->     <item android:state_focused="true"           android:color="#ff0000ff"/> <!-- focused -->     <item android:color="#ff000000"/> <!-- default --> </selector> 

then, in strings.xml added

<style name="darkbutton" parent="@android:style/theme.black">     <item name="android:background">@drawable/button_bg.xml</item>     <item name="android:textcolor">#000000</item> </style> 

the problem is, following error when try run application:

05-06 12:56:43.796: e/androidruntime(20672): fatal exception: main 05-06 12:56:43.796: e/androidruntime(20672): java.lang.runtimeexception: unable start activity componentinfo{com.example.unserekinder/com.example.unserekinder.neueskind}: android.view.inflateexception: binary xml file line #24: error inflating class <unknown> 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread.access$600(activitythread.java:141) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.os.handler.dispatchmessage(handler.java:99) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.os.looper.loop(looper.java:137) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread.main(activitythread.java:5041) 05-06 12:56:43.796: e/androidruntime(20672):    @ java.lang.reflect.method.invokenative(native method) 05-06 12:56:43.796: e/androidruntime(20672):    @ java.lang.reflect.method.invoke(method.java:511) 05-06 12:56:43.796: e/androidruntime(20672):    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-06 12:56:43.796: e/androidruntime(20672):    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-06 12:56:43.796: e/androidruntime(20672):    @ dalvik.system.nativestart.main(native method) 05-06 12:56:43.796: e/androidruntime(20672): caused by: android.view.inflateexception: binary xml file line #24: error inflating class <unknown> 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.createview(layoutinflater.java:613) 05-06 12:56:43.796: e/androidruntime(20672):    @ com.android.internal.policy.impl.phonelayoutinflater.oncreateview(phonelayoutinflater.java:56) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.oncreateview(layoutinflater.java:660) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:685) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.rinflate(layoutinflater.java:746) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-06 12:56:43.796: e/androidruntime(20672):    @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:270) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activity.setcontentview(activity.java:1881) 05-06 12:56:43.796: e/androidruntime(20672):    @ com.example.unserekinder.neueskind.oncreate(neueskind.java:22) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activity.performcreate(activity.java:5104) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-06 12:56:43.796: e/androidruntime(20672):    ... 11 more 05-06 12:56:43.796: e/androidruntime(20672): caused by: java.lang.reflect.invocationtargetexception 05-06 12:56:43.796: e/androidruntime(20672):    @ java.lang.reflect.constructor.constructnative(native method) 05-06 12:56:43.796: e/androidruntime(20672):    @ java.lang.reflect.constructor.newinstance(constructor.java:417) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.layoutinflater.createview(layoutinflater.java:587) 05-06 12:56:43.796: e/androidruntime(20672):    ... 24 more 05-06 12:56:43.796: e/androidruntime(20672): caused by: android.content.res.resources$notfoundexception: file res/drawable-xhdpi/button_bg.xml drawable resource id #0x7f020000 05-06 12:56:43.796: e/androidruntime(20672):    @ android.content.res.resources.loaddrawable(resources.java:1953) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.content.res.typedarray.getdrawable(typedarray.java:601) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.view.view.<init>(view.java:3330) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.widget.textview.<init>(textview.java:583) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.widget.button.<init>(button.java:107) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.widget.button.<init>(button.java:103) 05-06 12:56:43.796: e/androidruntime(20672):    ... 27 more 05-06 12:56:43.796: e/androidruntime(20672): caused by: org.xmlpull.v1.xmlpullparserexception: binary xml file line #4: <item> tag requires 'drawable' attribute or child tag defining drawable 05-06 12:56:43.796: e/androidruntime(20672):    @ android.graphics.drawable.statelistdrawable.inflate(statelistdrawable.java:178) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.graphics.drawable.drawable.createfromxmlinner(drawable.java:885) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.graphics.drawable.drawable.createfromxml(drawable.java:822) 05-06 12:56:43.796: e/androidruntime(20672):    @ android.content.res.resources.loaddrawable(resources.java:1950) 05-06 12:56:43.796: e/androidruntime(20672):    ... 32 more 

what problem?

i think must remove .xml extension @drawable/button_bg.xml in string.xml


Comments