【发布时间】:2012-09-07 18:30:54
【问题描述】:
我想为 android 中的按钮设置圆角,并在选择时更改按钮颜色。我正在做以下事情。
可绘制/push_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@color/green"/>
<item android:state_focused="true" android:drawable="@color/green"/>
<item android:state_focused="false" android:drawable="@color/green"/>
<item android:state_pressed="false" android:drawable="@color/red"/>
<item android:drawable="@drawable/push_button_background"/>
</selector>
可绘制/push_button_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
>
<solid android:color="#3F4040"/>
<corners
android:radius="7dp"
/>
</shape>
在代码中,我正在使用
android:background="@drawable/push_button"
这里的问题是,按钮颜色在选择和取消选择时设置正确。但是,圆角不起作用。
如何做到这一点? 如果我使用
android:background="@drawable/push_button_background"
然后,圆角可以使用,但选择时按钮颜色更改不起作用
如何实现?
我已经推荐了this 链接。即使那样也没有帮助!
【问题讨论】:
-
你可能需要用你想要的颜色和半径定义另外几个
drawables,并将@color/color更改为你定义的drawables。 -
@Aprian.. 你能详细说明一下吗?我是安卓新手!!可以给点样品吗?
标签: android background-color rounded-corners android-button