1

ボタンがあり、それらの背景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" />

button_selector.xml

<?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>

button_bg.xml

<?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>

button_bg_hover.xml

<?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、なぜペラーゼなのですか?正しいものは何ですか?

4

1 に答える 1

1

タグの位置が間違っている可能性があります。行を変更してください

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
  ..... 
</animation-list>

<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
  .....
</shape>
于 2013-02-09T13:37:53.407 に答える