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

From class android.widget.TextView
From class android.view.View

Inherited fields

From class android.view.View
From interface androidx.core.widget.AutoSizeableTextView

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

From class androidx.appcompat.widget.AppCompatTextView
From class android.widget.TextView
From class android.view.View
From class java.lang.Object
From interface androidx.core.view.TintableBackgroundView
From interface androidx.core.widget.TintableCompoundDrawablesView
From interface androidx.core.widget.AutoSizeableTextView
From interface android.view.ViewTreeObserver.OnPreDrawListener
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource

Public constructors

MaterialTextView

MaterialTextView (Context context)

Parameters
context Context

MaterialTextView

MaterialTextView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MaterialTextView

MaterialTextView (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

MaterialTextView

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

Parameters
context Context

attrs AttributeSet

defStyleAttr int

defStyleRes int

Public methods

setTextAppearance

void setTextAppearance (Context context, 
                int resId)

Parameters
context Context

resId int