Android Controls--button and ImageButton

Source: Internet
Author: User

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

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.