Android 12 Developer Preview is here! Try it out, and give us your feedback!

MaterialTextView

public class MaterialTextView
extends AppCompatTextView

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.TextView
       ↳ androidx.appcompat.widget.AppCompatTextView
         ↳ com.google.android.material.textview.MaterialTextView


A MaterialTextView is a derivative of AppCompatTextView that displays text to the user. To provide user-editable text, see EditText.

MaterialTextView supports the ability to read and apply android:lineHeight value from a TextAppearance style.

The following code sample shows a typical use, with an XML layout and code to modify the contents of the material text view:

 <LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent">
    <MaterialTextView
        android:id="@+id/text_view_id"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="@string/hello" />
 </LinearLayout>
 

This code sample demonstrates how to modify the contents of the material text view defined in the previous XML layout:

 public class MainActivity extends Activity {

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

To customize the appearance of MaterialTextView, see Styles and Themes.

Summary

Inherited constants

Inherited fields

Public constructors

MaterialTextView(Context context)
MaterialTextView(Context context, AttributeSet attrs)
MaterialTextView(Context context, AttributeSet attrs, int defStyleAttr)
MaterialTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)

Public methods

void setTextAppearance(Context context, int resId)

Inherited methods

Public constructors

MaterialTextView

public MaterialTextView (Context context)

Parameters
context Context

MaterialTextView

public MaterialTextView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MaterialTextView

public MaterialTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

MaterialTextView

public MaterialTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

setTextAppearance

public void setTextAppearance (Context context, 
                int resId)

Parameters
context Context

resId int