First off i want to say im attempting (and mostly succeeding) to use purely XML for styling purposes.
I ahve a list view, displaying the standard textview. Everyhting is working, including my custom xml defined drawables.
Except that my clear "buttons" turn green where transparent, as is the android 2.2 default. Is there any way to override this?
Attached below is the drawable code for the button. The Top colors for gradients are solid, bottoms are 100% transparent.
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="@color/butttop"
android:endColor="@color/buttbot"
android:angle="270"
android:dither="true"
/>
<!-- <stroke
android:width="1dp"
android:color="@color/stroke2" />-->
<corners
android:radius="20dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:endColor="@color/focustop"
android:startColor="@color/focusbot"
android:angle="270" />
<!--<stroke
android:width="1dp"
android:color="@color/stroke1" />-->
<corners
android:radius="20dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:endColor="@color/butttop"
android:startColor="@color/buttbot"
开发者_运维技巧 android:angle="90" />
<!--<stroke
android:width="1dp"
android:color="@color/stroke1" />-->
<corners
android:radius="20dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
next is the style pertaining to them, incase its needed. *Note: menubutt is the name of the above file.
<style name="DrawerItems1">
<item name="android:textSize">16px</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:shadowColor">#000000</item>
<item name="android:shadowDx">1</item>
<item name="android:shadowDy">1</item>
<item name="android:shadowRadius">3</item>
<item name="android:typeface">sans</item>
<item name="android:textStyle">bold</item>
<item name="android:background">@drawable/menubutt</item>
</style>
Answer found at https://stackoverflow.com/a/6201407/924939. Works for me.
You have to set android:listSelector="@drawable/listcolor" in ListView.
Then you define a drawable named listcolor.xml with a transparent solid color (or whatever you need), so that list item background will appear and default green or orange color will disappear:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
</shape>
This may also have to be mixed with the following code in your ListView:
android:cacheColorHint="@color/transparent"
android:background="@color/transparent"
精彩评论