Use the XML implementation button to change the focus setting background image. when the focus is obtained, the focus is obtained and pressed. when the focus is lost, the default focus is displayed...
Create Res/drawable/button. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Selector xmlns: Android = "http://schemas.android.com/apk/res/android"> <! -- Get focus --> <itemandroid: state_focused = "true" Android: state_pressed = "false" Android: drawable = "@ drawable/focusimage"/> <! -- Get the focus and press --> <itemandroid: state_focused = "true" Android: state_pressed = "true" Android: drawable = "@ drawable/clickimage"/> <! -- When the focus is lost --> <itemandroid: state_focused = "false" Android: state_pressed = "true" Android: drawable = "@ drawable/clickimage"/> <! -- Default --> <item Android: drawable = "@ drawable/normal"/> </selector>
Main. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <button Android: layout_margintop = "20dp" Android: Id = "@ + ID/button" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: TEXT = "button in different states" Android: Background = "@ drawable/button"/> </linearlayout>