Android--利用selector设置Button

如下图所示,为了实现这个效果:

这里写图片描述

主要有两部分:

  • 按键
  • 文字

按键

android:background="@drawable/button_selector"

button_selector.xml


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_normal" android:state_pressed="false"/> 

    <item android:drawable="@drawable/btn_pressed" android:state_pressed="true"/> 

selector>

btn_pressed.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#020c41">solid> 
    <stroke android:width="1dp" android:color="#FFFFFF">stroke> 
shape>

btn_normal.xml


<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@color/white">solid>
    <stroke android:width="1dp" android:color="#FFFFFF">stroke>
shape>

文字

android:textColor="@drawable/text_color_selector"

text_color_selector.xml


<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="#57565D" android:state_pressed="false"/>
    <item android:color="#FFFFFF" android:state_pressed="true"/>
selector>

你可能感兴趣的:(Android)