RadioButton、CheckBox去除選中時的動畫陰影效果

CheckBox默認選中和取消選中都有個灰色陰影效果,去除方法如下:

方法一:(評論區建議)

直接使用background屬性。顏色或圖片,使用AS3.1版本,還是需要添加android:button="@null")

android:background="@drawable/ic_launcher"
android:background="@android:color/transparent"

方法二:(AS3.0上不能使用)

1.在CheckBox的佈局中添加button屬性

android:button="@null"

2.在res/drawable文件夾下新建一個selector文件check_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_launcher" android:state_checked="true"></item>
    <item android:drawable="@drawable/ic_launcher_round" android:state_checked="false"></item>
</selector>
解析:該xml文件中有兩個item,第一個是控件選中狀態爲true時展示的圖片爲ic_launcher,第二個是選中狀態爲false的情況。

selsector不但有是否選中,還有許多狀態,如:state_focused 是否聚焦

3.在CheckBox的佈局中添加background屬性

android:background="@drawable/check_selector"
<CheckBox
        android:id="@+id/check_child"
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:checked="false"
        android:gravity="center"
        android:button="@null"
        android:background="@drawable/check_selector"
        android:layout_centerVertical="true"
        />

運行後,陰影效果將不會再顯示


發佈了45 篇原創文章 · 獲贊 49 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章