Android應用開發之(你必須知道的android selector下的屬性值)

來源:互聯網
上載者:User

 

在res/drawable檔案夾新增一個檔案,此檔案設定了圖片的觸發狀態,你可以設定 state_pressed,state_checked,state_pressed,state_selected,state_focused,state_enabled 等幾個狀態:

android:state_pressed

Boolean. "true" if this item should be used when the object is pressed (such as when a button is touched/clicked); "false" if this item should be used in the default, non-pressed state.

如果是true,當被點擊時顯示該圖片,如果是false沒被按下時顯示預設。

android:state_focused

Boolean. "true" if this item should be used when the object is focused (such as when a button is highlighted using the trackball/d-pad); "false" if this item should be used in the default, non-focused state.

true,獲得焦點時顯示;false,沒獲得焦點顯示預設。

android:state_selected

Boolean. "true" if this item should be used when the object is selected (such as when a tab is opened); "false" if this item should be used when the object is not selected.

true,當被選擇時顯示該圖片;false,當未被選擇時顯示該圖片。

android:state_checkable

Boolean. "true" if this item should be used when the object is checkable; "false" if this item should be used when the object is not checkable. (Only useful if the object can transition between a checkable and non-checkable widget.)

true,當CheckBox能使用時顯示該圖片;false,當CheckBox不能使用時顯示該圖片。

android:state_checked

Boolean. "true" if this item should be used when the object is checked; "false" if it should be used when the object is un-checked.

true,當CheckBox選中時顯示該圖片;false,當CheckBox為選中時顯示該圖片。

android:state_enabled

Boolean. "true" if this item should be used when the object is enabled (capable of receiving touch/click events); "false" if it should be used when the object is disabled.

true,當該組件能使用時顯示該圖片;false,當該組件不能使用時顯示該圖片。

android:state_window_focused

Boolean. "true" if this item should be used when the application window has focus (the application is in the foreground), "false" if this item should be used when the application window does not have focus (for example, if the notification shade is pulled down or a dialog appears).

true,當此activity獲得焦點在最前面時顯示該圖片;false,當沒在最前面時顯示該圖片。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true"

android:drawable="@drawable/button_pressed"/><!--
pressed -->

<item android:state_focused="true"

android:drawable="@drawable/button_focused"/><!--
focused -->

<item android:drawable="@drawable/button_normal"/><!--
default
-->
</selector>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.