Android's Selector

Source: Internet
Author: User
Tags manual writing

To add a background image to the button, you need to put the picture in selector for the button to use.
The first time the XML obtained to selector was searched from the Internet. have been thinking, if you need to rely on Eclipse or manual writing selector, can you get it out?
Fortunately, Eclipse supports the generation of the selector framework, which can only be said as a framework, because selector's content can only be entered manually.
The steps for Eclipse to support building the selector framework are as follows:
In Eclipse packge Explorer, right-click New-----Android XML File:
Resource Type: drawable; Root elemant selected: Seletor (file name: Connect_button_press, cannot be capitalized)
Next, Finish, generate the following XML file:

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

Add item items as needed, such as:

<android:state_pressed= "true"  android:drawable= "@drawable/net_ Connect "/>  <android:drawable=" @drawable/net_ Noconnect "/>  

In the Button XML, add:

android:background= "@drawable/connect_button_press"  

In Java code, you can call the following:

Btnnetstatus.setbackgroundresource (R.drawable.net_noconnect);  

Android's Selector

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.