生活随笔
收集整理的這篇文章主要介紹了
定制知识积累
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
若對(duì)系統(tǒng)自帶的widget外觀不滿意,可以進(jìn)行定制,原理是修改widget屬性對(duì)應(yīng)的drawable,操作步驟如下:
1.在android系統(tǒng)的styles.xml/theme.xml中找到控件的屬性所對(duì)應(yīng)的drawable(圖片或selector);
2.在項(xiàng)目的styles.xml中自定義風(fēng)格,繼承系統(tǒng)風(fēng)格,修改相應(yīng)的drawable;
3.在layout.xml中設(shè)置widget的style = "@style/自定義style";
CheckBox定制
在sdk/platforms/android-**/data/res文件夾內(nèi)搜索"styles.xml",并打開(kāi);找到所需控件的style:
<style name="Widget.CompoundButton.CheckBox"><item name="android:button">?android:attr/listChoiceIndicatorMultiple</item></style>屬性開(kāi)頭是"?",表明引用了系統(tǒng)的theme屬性;繼續(xù)在當(dāng)前目錄內(nèi)搜索"theme.xml",打開(kāi)后找到"listChoiceIndicatorMultiple":
<item name="listChoiceIndicatorMultiple">@android:drawable/btn_check</item>再次搜索"btn_check",可以找到"btn_check.xml":<selector xmlns:android="http://schemas.android.com/apk/res/android"><!-- Enabled states --><item android:state_checked="true" android:state_window_focused="false"android:state_enabled="true"android:drawable="@drawable/btn_check_on" /><item android:state_checked="false" android:state_window_focused="false"android:state_enabled="true"android:drawable="@drawable/btn_check_off" /><item android:state_checked="true" android:state_pressed="true"android:state_enabled="true"android:drawable="@drawable/btn_check_on_pressed" /><item android:state_checked="false" android:state_pressed="true"android:state_enabled="true"android:drawable="@drawable/btn_check_off_pressed" /><item android:state_checked="true" android:state_focused="true"android:state_enabled="true"android:drawable="@drawable/btn_check_on_selected" /><item android:state_checked="false" android:state_focused="true"android:state_enabled="true"android:drawable="@drawable/btn_check_off_selected" /><item android:state_checked="false"android:state_enabled="true"android:drawable="@drawable/btn_check_off" /><item android:state_checked="true"android:state_enabled="true"android:drawable="@drawable/btn_check_on" /><!-- Disabled states --><item android:state_checked="true" android:state_window_focused="false"android:drawable="@drawable/btn_check_on_disable" /><item android:state_checked="false" android:state_window_focused="false"android:drawable="@drawable/btn_check_off_disable" /><item android:state_checked="true" android:state_focused="true"android:drawable="@drawable/btn_check_on_disable_focused" /><item android:state_checked="false" android:state_focused="true"android:drawable="@drawable/btn_check_off_disable_focused" /><item android:state_checked="false" android:drawable="@drawable/btn_check_off_disable" /><item android:state_checked="true" android:drawable="@drawable/btn_check_on_disable" /></selector>可知系統(tǒng)定義了該widget選中/未選中時(shí)的圖片,因此定制時(shí),通過(guò)創(chuàng)建style,繼承系統(tǒng)的checkbox風(fēng)格,引用自定義selector即可;在項(xiàng)目drawable目錄下創(chuàng)建"selector_my_checkbox.xml":
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_checked="true" android:drawable="@drawable/my_checkbox_selected" ></item><item android:drawable="@drawable/my_checkbox_unselected"></item>
</selector>在項(xiàng)目values/styles.xml中自定義style:
<style name="MyCheckBox" parent="@android:style/Widget.CompoundButton.CheckBox"><item name="android:button">@drawable/selector_my_checkbox</item></style>設(shè)置CheckBox的屬性即可:
<CheckBoxandroid:layout_width="wrap_content"android:layout_height="wrap_content"style="@style/MyCheckBox"/>
轉(zhuǎn)載于:https://www.cnblogs.com/lynxz0620/p/4384928.html
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀
總結(jié)
以上是生活随笔為你收集整理的定制知识积累的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。