I am posting this to determine if this is a bug I should file or my own 
operator error. Any input would be appreciated.

I was attempting to use a theme to change the background of all buttons in 
my application. 
Instead of using a 
StateListDrawable<http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html>
 I 
am trying a 
ColorStateList<http://developer.android.com/reference/android/content/res/ColorStateList.html>
. 

My theme is simply:
*<?xml version="1.0" encoding="utf-8"?>*
*<resources>  *
*  <style name="EarthToneTheme" parent="CustomLightTheme">*
*      <item name="android:buttonStyle">@style/EarthtoneButton</item>*
*      <!--  <item 
name="android:listViewStyle">@style/EarthtoneListView</item>*
*      <item name="android:tabWidgetStyle">@style/EarthtoneTabWidget</item> 
-->*
*  </style>*
*</resources>*

My style is:
*<?xml version="1.0" encoding="utf-8"?>*
*<resources>*
*    <style name="EarthtoneButton" parent="android:Widget.Button">*
*        <item 
name="android:background">@color/button_selector_earthtone</item>*
*        <!--  <item 
name="android:background">@color/earthtone_darkblue</item> -->*
*    </style>*
*</resources>* 

My 
ColorStateList<http://developer.android.com/reference/android/content/res/ColorStateList.html>
 is 
in res/color/ and is:
*<?xml version="1.0" encoding="utf-8"?>*
*<selector xmlns:android="http://schemas.android.com/apk/res/android"; >*
*    <!-- Normal -->*
*    <item android:state_window_focused="false" android:state_enabled="true"
*
*        android:color="@color/earthtone_darkblue" />*
*    <!-- Pressed -->*
*    <item android:state_pressed="true" *
*        android:color="@color/earthtone_darkgreen" />*
*    <!-- Selected -->*
*    <item android:state_focused="true" android:state_enabled="true"*
*        android:color="@color/earthtone_mediumgreen" />*
*    *
*    <item android:state_window_focused="false" 
android:state_enabled="false"*
*        android:color="@color/earthtone_lightgrey" />*
*    <item android:state_enabled="true"*
*        android:color="@color/earthtone_darkblue" />*
*    <item android:state_focused="true"*
*        android:color="@color/earthtone_mediumgreen" />*
*    <item android:color="@color/earthtone_darkblue" />*
*</selector>*

Below is my sesson data and stack trace.

*Eclipse session data:*
eclipse.buildId=M20110909-1335
java.version=1.7.0_02
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86 -product 
org.eclipse.epp.package.java.product

*Exception Stack Trace:*
org.xmlpull.v1.XmlPullParserException: Binary XML file line #5: <item> tag 
requires a 'drawable' attribute or child tag defining a drawable
at 
android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:167)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
at 
com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:208)
at 
com.android.layoutlib.bridge.android.BridgeTypedArray.getDrawable(BridgeTypedArray.java:731)
at android.view.View.<init>(View.java:1885)
at android.widget.TextView.<init>(TextView.java:327)
at android.widget.Button.<init>(Button.java:108)
at android.widget.Button.<init>(Button.java:104)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
at 
com.android.layoutlib.bridge.android.BridgeInflater.onCreateView(BridgeInflater.java:84)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
at 
com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:129)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at 
com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
at 
com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at 
com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at 
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1323)
at 
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1077)
at 
com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$ConfigListener.onThemeChange(GraphicalEditorPart.java:517)
at 
com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.onThemeChange(ConfigurationComposite.java:2272)
at 
com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite.access$10(ConfigurationComposite.java:2260)
at 
com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigurationComposite$8.widgetSelected(ConfigurationComposite.java:524)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
at 
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at 
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at 
org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at 
org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at 
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at 
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)

I am trying to figure out why XmlPullParserException is requiring a 
drawable attribute? This is a ColorStateList so it should look for and use 
the color attribute.
I can substitute a color for the ColorStateList in my style and all will 
work as expected. I can substitute a StateListDrawable and all works fine. 
If I add both drawable and color attributes to my state selector xml the 
drawable attribute will be used and the color attribute either covered up 
or ignored.
I can not get a ColorStateList to work with a button.

any help using a theme and ColorStateList with buttons would be very 
helpful. Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to