Follow Android 007, get a full set of Free Android development learning materials

What is the Button

A Button is a UI control that displays a Button.

Based on the sample

1. Common button

rendering

code

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I am the Button" />
Copy the code

2. Set case-sensitive display (default: all caps)

rendering

code

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm a case sensitive Button."
    android:textAllCaps="false" />
Copy the code

3. Set the font size

rendering

code

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm a 20-point Button."
    android:textSize="20sp" />
Copy the code

4. Set the color

rendering

code

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm a red Button."
    android:textColor="#FF0000"/>
Copy the code

5. Set bold

rendering

code

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="I'm Button in bold."
    android:textStyle="bold" />
Copy the code

Basic sample complete source code

Gitee.com/cxyzy1/edit…

Common Attributes

The property name use
android:layout_width Set the width of the control to match_parent(same as the parent control),wrap_content(automatic scaling based on the content), fixed values (such as 200dp)
android:layout_height Set the height of the control to match_parent(same as the parent control),wrap_content(automatic scaling based on the content), fixed value (such as 200dp)
android:gravity Control for internal alignment
android:background Set the background, which can be a color value (such as #FF0000) or an image
android:visibility Optional values: Visible (display), invisible(hidden, but still occupies UI space),gone(hidden, and does not occupy UI space)
android:text Setting text content
android:textSize Set the font size
android:textColor Set the color
android:textStyle Set the font style. Optional values: Normal (normal),bold(italic)
android:lines The maximum number of lines of text to display
android:ellipsize Displays the position of the ellipsis when the text cannot be displayed in its entirety. Optional values :end(end),start(beginning),middle(middle),marquee(running light), None (ellipsis not shown)
android:textAllCaps All caps, optional :true(all caps, default),false(case sensitive)

More properties and actual effects can be experienced in the development tool.


Android development tutorial series summary

Development language learning

Kotlin language basics

UI control learning series

UI control _TextView UI control _EditText UI control _Button UI control _ImageView UI control _RadioButton UI control _CheckBox UI control _ProgressBar

Follow the headlines to get the latest articles: