我有按钮,我想为他们设置背景xml,当用户按任意按钮我想改变它的背景时,我就像这样工作
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="#FFFFFF"
android:gravity="center"
android:background="@drawable/button_selector"
android:text="@string/b_cancel" />
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_bg" android:state_pressed="false" android:state_selected="false"/>
<item android:drawable="@drawable/button_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/button_bg_hover" android:state_pressed="false" android:state_selected="true"/>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding android:top="10dip"
android:bottom="10dip"/>
<!-- Gradient Bg for listrow -->
<gradient
android:useLevel="false"
android:angle="270"
android:centerColor="#000000"
android:endColor="#FFFFFF"
android:startColor="#808080" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<padding
android:bottom="10dip"
android:top="10dip" />
<!-- Gradient Bg for Button -->
<gradient
android:angle="270"
android:centerColor="#000000"
android:endColor="#FF0000"
android:startColor="#808080" />
</animation-list>
它作为背景很好但是当我按下按钮时它会变成全白,激发我的button_bg_hover
,为什么要pelase?什么是正确的?
答案 0 :(得分:1)
可能是错位的-tag,改变了行
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
.....
</animation-list>
到
<shape xmlns:android="http://schemas.android.com/apk/res/android">
.....
</shape>