TextView Use Details

Posted by maiza on Tue, 06 Aug 2019 04:10:34 +0200

Most Recommended Articles: Welcome to Collection
Android dry goods sharing

Read for five minutes, ten o'clock a day, and study with you for life, here is the programmer Android

This article mainly introduces some of the knowledge points in Android development. By reading this article, you will get the following:

1. TextView Inheritance
2. Examples of simple use of TextView
3. TextView Horselight Effect
4. Attribute of ellipsis at the end of TextView
5. TextView color, font size properties
6. TextView Location Properties
7. TextView contains picture hyperlink background vertical median attribute

1. TextView Inheritance

The TextView inheritance relationship is as follows:

java.lang.Object
   ↳    android.view.View
        ↳    android.widget.TextView

The TextView official api documentation is as follows:

Click to check the TextView document

2. Examples of simple use of TextView

Use xml layout to dynamically set TextView with java code.

    1. The xml layout is as follows
 <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent">
    <TextView
        android:id="@+id/text_view_id"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/hello" />
 </LinearLayout>
    1. The following methods are used in java code:
 public class MainActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         final TextView helloTextView = (TextView) findViewById(R.id.text_view_id);
         helloTextView.setText(R.string.user_greeting);
     }
 }
 

3. TextView Horselight Effect

The TextView horselight effect can be used in the following ways:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text="1. Horselight Effect  eg: ellipsize Welcome to Programmers Android  Get more Android Develop materials, dry goods, learning videos!"
        android:textSize="16sp" />

The results are as follows:

4. Attribute of ellipsis at the end of TextView

The ellipsis property at the end of TextView is implemented as follows:


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:singleLine="true"
        android:text="2. End Ellipsis Effect   eg:   ellipsize Attribute controls the position of the ellipsis (start mid-end jogging light)  "
        android:textSize="16sp" />

The results are as follows:

5. TextView color, font size properties

TextView font color and size are set as follows:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="3. Font color and size eg: textColor gules  textSize 16sp"
        android:textColor="#F00"
        android:textSize="16sp" />

The results are as follows:

6. TextView Location Properties

The TextView Location Centering property is set as follows:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:paddingBottom="10dp"
        android:paddingTop="10dp"
        android:text="4. Font Position Properties  eg: Centered "
        android:textColor="#FF6100"
        android:textSize="16sp" />

The results are as follows:

7. TextView contains picture hyperlink background vertical median attribute

TextView Set Hyperlink Click, Left Picture, Vertical Medium Properties as follows:

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:autoLink="email"
        android:background="@android:color/white"
        android:drawableLeft="@drawable/ic_launcher"
        android:gravity="center_vertical"
        android:linksClickable="true"
        android:text="V.\n1.Include picture on left  drawableLeft \n2.Background color white  background \n3. Mailbox hyperchain:  autoLink eg : 1150580768@qq.com"
        android:textColor="@android:color/black"
        android:textSize="16sp" />

The results are as follows:

This is the end of the article. If something is wrong, you are welcome to make suggestions and corrections.At the same time, we look forward to your attention, thank you for your reading, thank you!

Topics: Android Attribute Java xml