Button--Buttons
ImageButton--Picture button
button and ImageButton features
1. Common features
Can be used as a button to generate click events
2. Different points:
(1) Button has the Text property, ImageButton has no
(2) ImageButton has the SRC attribute, button has no
3. Create a noticeable click effect
Achieve the effect of button and ImageButton
Note: We generally do not write the Android:text information directly but in the Res/values/strings.xml file
Add Button_name to String.xml:
<name= "Button_name"> login </string>
The button references the value of Button_name through @string/button_name:
< Button Android:id = "@+id/button1" android:layout_width= "Match_parent" android:layout_height= "Wrap_ Content " android:text=" @string/button_name "/>
ImageButton:
< ImageButton Android:id = "@+id/imagebutton1" android:layout_width= "Match_parent" android:layout_height= "Wrap_ Content " android:src=" @drawable/ic_launcher "/>
<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" > <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "@string/button_name" /> <ImageButtonAndroid:id= "@+id/imagebutton1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:src= "@drawable/ic_launcher" /></LinearLayout>
Fragment_main.xml
<?XML version= "1.0" encoding= "Utf-8"?><Resources><StringName= "App_name">buttonimagebutton</String><StringName= "Hello_world">hello world!</string> <string name= " Action_settings ">settings</string> <name= "Button_name" > login </string< Span style= "color: #0000ff;" >></resources
Strings.xml
Android pushbutton button and ImageButton