如果去追一下textAppearanceSmall可以找到
<style name="TextAppearance.Small">
<item name="android:textSize">14sp</item>
<item name="android:textColor">?textColorSecondary</item>
</style>
這說明textAppearanceSmall這個設定同時設定了字體大小以及顏色。我們有興趣的地方在顏色的設定,所以追蹤一下顏色可以發現
以及在....res\color\目錄下的secondary_text_dark.xml檔案
<?xml version="1.0" encoding="utf-8"?>
.......
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="false" android:color="@android:color/dim_foreground_dark_disabled"/>
<item android:state_window_focused="false" android:color="@android:color/dim_foreground_dark"/>
<item android:state_selected="true" android:state_enabled="false" android:color="@android:color/dim_foreground_dark_inverse_disabled"/>
<item android:state_pressed="true" android:state_enabled="false" android:color="@android:color/dim_foreground_dark_inverse_disabled"/>
<item android:state_selected="true" android:color="@android:color/dim_foreground_dark_inverse"/>
<item android:state_activated="true" android:color="@android:color/bright_foreground_dark_inverse"/>
<item android:state_pressed="true" android:color="@android:color/dim_foreground_dark_inverse"/>
<item android:state_enabled="false" android:color="@android:color/dim_foreground_dark_disabled"/>
<item android:color="@android:color/dim_foreground_dark"/> <!-- not selected -->
</selector>
這份文檔在Android裡面稱做State List,一般用來變換一個繪圖元件在不同狀態下的顯示圖片。
狀態的定義有 (原文照拷比較原汁原味)
android:state_pressed
android:state_focused
android:state_hovered
Introduced in API level 14.
android:state_selected
The selected state is used when focus (
android:state_focused
) is not sufficient (such as when list view has focus and an item within it is selected with a d-pad).android:state_checkable
android:state_checked
android:state_enabled
android:state_activated
Introduced in API level 11.
android:state_window_focused
回到secondary_text_dark.xml這份文件,每一個<item ... />表示一個狀態,所以在寫的時候需要確認到每一個<item ... />之間是互斥的關係。所以
<item android:state_pressed="true" android:state_enabled="false" android:color="@android:color/dim_foreground_dark_inverse_disabled"/>
表示當此TextView被按住(state_pressed="true")且此TextView是被除能的(disabled, 看上面的英文會比較理解這在說什麼)則此TextView的顏色變換成dim_foreground_dark_inverse_disabled所定義 (查一下它的顏色代碼是 #80323232)
我們常用State List來變換按鈕的狀態,譬如壓下按鈕然後放開會有一個顏色的變換讓使用者感覺到按鈕確實有被觸碰到。xml範例如下
<!-- filename: buttonbackground.xml -->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/未按下時的圖片.png"
android:state_pressed="false"
android:state_selected="false"/>
<item
android:drawable="@drawable/ 按下時的圖片.png "
android:state_pressed="true"/>
</selector>
然後將Button的視圖的background屬性指向的這xml檔案即可。
Get a $50 free chip bonus at Slots of Vegas
回覆刪除Slots of Vegas Online 출장안마 Casino Review https://septcasino.com/review/merit-casino/ - novcasino Welcome Bonus: Get $50 free chip bonus at Slots of Vegas Casino! Read on to learn aprcasino more about the latest Rating: 3.5 · Review by Casino Roll 바카라 사이트