Android Control layout ToggleButton button picture and text

Source: Internet
Author: User

The ToggleButton control has checked properties that are useful for function buttons to toggle state

Here is an example of the effect and layout of the phone's open Dtmftwelvekeydialer button

Activity_main.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " >       <ToggleButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@drawable/button_incall"Android:drawabletop= "@drawable/icon_keyboard_bg"Android:texton= "Keyboard"Android:textoff= "Keyboard"android:textsize= "32dip"Android:textcolor= "#FFFFFF"        />        </LinearLayout>

Where Drawabletop refers to the Icon_keyboard_bg.xml

Icon_keyboard_bg.xml

<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android">        <Itemandroid:state_pressed= "true"android:drawable= "@drawable/icon_keyboard_up_pressed"        />        <Itemandroid:state_checked= "true"android:drawable= "@drawable/icon_keyboard_up"        />        <Itemandroid:state_checked= "false"android:drawable= "@drawable/icon_keyboard_down"        />        <Itemandroid:drawable= "@drawable/icon_keyboard_down"        /></selector>

This allows you to switch between three different state images when the button is clicked.

1. Effect in the natural state

2. Press the button effect

3. Effect of attribute checked= "true"

The problem of internationalization should be paid attention to in actual use string, spacing, size should not be hard-coded

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.