【Android-View】Android View控相關低頻屬性

目錄

1. TextView

2. EditText

3. ImageView

4. CheckBox

4.1 調整原生樣式CheckBox的大小

4.2 調整原生樣式CheckBox的顏色



1. TextView

 

2. EditText

 

3. ImageView

 

4. CheckBox

 

4.1 調整原生樣式CheckBox的大小

【問題】即便設置layout_width和layout_height爲wrap_content的時候發現他還是很大。
【方案】可使用【scaleX/Y】屬性:

<CheckBox
    android:layout_width="wrap_content"
    android:layout_height="wrap_content
    android:scaleX="0.6"
    android:scaleY="0.6"/>

【參考】https://blog.csdn.net/lintcgirl/article/details/48312309

 

4.2 調整原生樣式CheckBox的顏色

【問題】原生樣式的CheckBox帶有點選動畫,選中爲綠色,未選中爲灰色,且自帶點擊波紋效果。但如要修改點選顏色,卻發現源碼中使用的是圖片而非色值。
【方案】自定義樣式,並引用。

① 在[module>src>main>res>values>styles.xml]文件中,自定義樣式。
其中“colorControlNormal”爲未選中時的顏色,“colorControlActivated”爲選中之後的顏色,色值可自定義:

    <style name="InfoCheckBox" parent="Theme.AppCompat.Light">
        <item name="colorControlNormal">@color/colorGray</item>
        <item name="colorControlActivated">@color/colorRed</item>
    </style>

② 在CheckBox控件中使用該自定義樣式,注意,使用【android:theme】屬性,而非“style

<CheckBox
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:theme="@style/MyCheckBox" />

【參考】https://blog.csdn.net/ulddfhv/article/details/83047055

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章