【android】设置View字体点击变色和边框背景设置

1.设置字体变色

selector_orange_white.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--黑白字体颜色切换 默认是黑 点击之后是白-->
    <item android:color="@color/oranger" android:state_pressed="false" android:state_enabled="true"/>
    <item android:color="@color/white" android:state_pressed="true" android:state_enabled="true"/>
    <item android:color="@color/invaild" android:state_enabled="false"/>"
</selector>



2.设置背景变化

selector_highlight_button.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_pressed="false" android:drawable="@drawable/shape_button_highlight"/>
    <item android:state_pressed="true" android:drawable="@drawable/shape_button_highlight_clicked"/>
</selector>

shape_button_hightlight.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
            android:width="1dp"
            android:color="#ff8500"
            />
    <solid
            android:color="@color/white"
            />
    <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp"
            >
    </padding>
</shape>

shape_button_highlight_clicked.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <stroke
            android:width="1dp"
            android:color="#ff8500"
            />
    <solid
            android:color="#ffb055"
            />
    <padding
            android:bottom="1dp"
            android:left="1dp"
            android:right="1dp"
            android:top="1dp"
            >
    </padding>
</shape>

最后的使用:

android:background="@drawable/selector_highlight_button"
android:textColor="@color/selector_orange_white"




你可能感兴趣的:(android,字体,button,边框,点击)