Android development tips: buttons in different States

Source: Internet
Author: User

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>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.