内容简介:http://stackoverflow.com/questions/12427107/how-to-set-button-selection-color-along-with-rounded-corners-in-android
我想在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 的链接.即使没有帮助!
我已经找到答案我的问题,几个审判&错误尝试.
这是解决方案.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true">
<shape >
<solid android:color="@color/green"/>
<corners
android:radius="7dp"/>
</shape>
</item>
<item android:state_focused="true" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/green"/>
<corners
android:radius="7dp"/>
</shape>
</item>
<item android:state_focused="false" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/red"/>
<corners
android:radius="7dp"/>
</shape>
</item>
<item android:state_pressed="false" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/red"/>
<corners
android:radius="7dp"
/>
</shape>
</item>
</selector>
http://stackoverflow.com/questions/12427107/how-to-set-button-selection-color-along-with-rounded-corners-in-android
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Nature of Code
Daniel Shiffman / The Nature of Code / 2012-12-13 / GBP 19.95
How can we capture the unpredictable evolutionary and emergent properties of nature in software? How can understanding the mathematical principles behind our physical world help us to create digital w......一起来看看 《The Nature of Code》 这本书的介绍吧!