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