selector: Set the value of the background property in selector

  • 2021-01-14 06:35:36
  • OfStack

This article illustrates how to set the value of the background property in selector. To share with you for your reference, as follows:

state_pressed, state_checked, state_pressed, state_selected, state_focused, state_enabled, state_pressed, state_checked, state_pressed, state_selected, state_focused, state_enabled, state_pressed, state_checked

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.
If true is selected, the image will be displayed when clicked. If false is not selected, the image will be displayed by default.

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, displayed when focus is obtained; ES36en, not getting focus display by default.

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, which displays the image when selected; false, displays the image when it is not selected.

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, display the image when CheckBox is available; false, which displays the image when CheckBox is not available.

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, the image is displayed when CheckBox is selected; false, the image is displayed when CheckBox is selected.

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, which displays the image when the component is available; ES76en, which displays the image when the component is not available.

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, which displays the image when this activity is focused on the front; false, which displays the image when it is not at the front.


<?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 -->
  <itemandroid:drawable="@drawable/button_normal"/><!-- default -->
</selector>

For more information on Android development, please check out the Android development introductory and advanced tutorial.

Hope this article described to everyone Android program design is helpful.


Related articles: