Android 默认选择绿色通过透明背景视图显示
首先,我想说我正在尝试(并且大部分成功)使用纯 XML 来实现样式设计目的。
我有一个列表视图,显示标准文本视图。一切正常,包括我自定义的 xml 定义的可绘制对象。
除了我的透明“按钮”在透明处变成绿色,就像 android 2.2 默认值一样。有什么办法可以覆盖这个吗?
下面附上按钮的可绘制代码。渐变的顶部颜色是纯色,底部是 100% 透明。
<?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>
接下来是与它们相关的样式,以防需要。 *注:menubutt是上述文件的名称。
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案位于https://stackoverflow.com/a/6201407/924939。对我有用。
您必须在 ListView 中设置 android:listSelector="@drawable/listcolor" 。
然后,您定义一个名为 listcolor.xml 的可绘制对象,具有透明的纯色(或您需要的任何颜色),以便列表项背景将出现,默认的绿色或橙色将消失:
这可能也必须是在 ListView 中与以下代码混合:
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:
This may also have to be mixed with the following code in your ListView: