Android股票按钮让它变得坚固

时间:2013-08-22 15:41:12

标签: android android-button

嗨我试图让Android股票按钮稳固,但在按下更改颜色时仍然包含小动画。任何帮助都是极好的。这是我到目前为止所做的。

   <?xml version="1.0" encoding="UTF-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="0dp" android:color="#000000" />
<solid android:color="#ffffff"/>
<corners android:radius="1px"/>
<padding android:left="5dp" android:top="3dp" android:right="5dp" android:bottom="3dp"    /> 
</shape>

1 个答案:

答案 0 :(得分:0)

对于选择并单击,您可以使用选择器示例:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@color/clr_main_green_pressed" android:state_selected="true" android:state_window_focused="false"/>
    <item android:drawable="@color/clr_main_green_pressed" android:state_selected="true"/>
    <item android:drawable="@color/clr_main_green_pressed" android:state_pressed="true" android:state_selected="false"/>
    <item android:drawable="@android:color/white" android:state_selected="false"/>

</selector>

某些形状/颜色/变化例如:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners android:radius="12dp" />

    <solid android:color="@android:color/white" />

    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />

</shape>

并将两者结合起来使用:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item android:drawable="@drawable/rounded_border"/>
    <item android:drawable="@drawable/selector_button"/>

</layer-list>