1. Brief introduction
2. Features
3. Implement button and ImageButton3.1 using button
Layout file Definition button
Strings.xml definition Constants ( Chinese characters are generally defined in Strings.xml, layout files are referenced by @string/name )
Rationale: Files under the RES resource file will generate an ID in the Gen directory R.java, uniquely identifying a resource.
Effect:
3.1 Using ImageButton
Layout file: The background color is set to black, the image is referenced by src (height is the size of the package picture), if the picture is introduced via background is the picture fits the button size
<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:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Mainactivity " > <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:background= "#000000"Android:layout_height= "Wrap_content"android:src= "@drawable/ic_launcher" /></LinearLayout>
Effect:
Summary:
button to set the text, you can not set the picture
ImageButton can set the picture, if you want to set the text can be introduced by background or SRC introduction of a text-based picture to achieve the text button effect.
Android Controls--button and ImageButton