SoFunction
Updated on 2025-04-10

Introduction to Android TextView text control

explain

TextView is one of the most basic and most commonly used components of Android, and it bears the heavy responsibility of displaying text. It should be noted that the text content displayed cannot be modified directly by the user on the interface. However, as a programmer, you can modify the content and various properties of the TextView through background code. Also note that TextView controls need to be placed in containers, such as LinearLayout containers (usually, controls must be placed in containers).

Introduction to basic properties

property illustrate
id Set a component id (unique), get the object through findViewById() method, and then make relevant settings
layout_width Set the component width, which can fill in numbers and enum values ​​provided by Android, two enum values ​​provided by Android:match_parent: Matches the parent class width (minus padding) (after Level 8, instead of the abandoned fill_parent),wrap_content: Components should be large enough to have their contents (plus padding, of course no more than their parent class).
layout_height Set the component height, which can fill in numbers and enum values ​​provided by Android, and two enum values ​​provided by Android:match_parent: Height matches to the parent class (minus padding) (after Level 8, instead of the abandoned fill_parent),wrap_content: Components should be large enough to have their contents (plus padding, of course no more than their parent class).
text Set the displayed text content
background Set background color (or background image)
textColor Set font color
textStyle Set the font style, three optional values: normal (no effect), bold (bold), italic (italic)
textSize Font size, generally used sp
gravity Alignment direction of content

Example:

    <TextView
        android:
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:text="Revise"
        android:textColor="@color/white"
        android:textSize="90dp"
        android:textStyle="bold"
        android:gravity="center"
        android:background="@color/black"/>

Background call

The Java background is called through ID.
Notice:Java will overwrite the original content of the corresponding TextView.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);

        TextView tv = findViewById(.tView1);
        ("TextView1");
    }

Summarize

This is the end of this article about the introduction of Android TextView text controls. For more related contents of Android TextView text controls, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!