# MaterialTextView

[View Source](https://github.com/material-components/material-components-android/blob/1.14.0/lib/java/com/google/android/material/textview/MaterialTextView.java)

*** ** * ** ***


```
public class MaterialTextView
```

<br />

*** ** * ** ***

A MaterialTextView is a derivative of AppCompatTextView that displays text to the user. To provide user-editable text, see android.widget.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](https://developer.android.com/guide/topics/ui/themes.html).

For more information, see the [component developer guidance](https://github.com/material-components/material-components-android/blob/master/docs/components/MaterialTextView.md).

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context)(Context context)` |
| `https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context,AttributeSet)(Context context, AttributeSet attrs)` |
| `https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context,AttributeSet,int)(Context context, AttributeSet attrs, int defStyleAttr)` |
| `[MaterialTextView](https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context,AttributeSet,int,int))( Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes )` **This method is deprecated.** Since AppCompatTextView does not provide a 4 arg constructor, the defStyleRes argument will be ignored. <br /> |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#setTextAppearance(Context,int)(Context context, int resId)` |

## Public constructors

### MaterialTextView

```
public MaterialTextView(Context context)
```

### MaterialTextView

```
public MaterialTextView(Context context, AttributeSet attrs)
```

### MaterialTextView

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

### MaterialTextView

```
public [MaterialTextView](https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context,AttributeSet,int,int))(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Since AppCompatTextView does not provide a 4 arg constructor, the defStyleRes argument will be ignored. Please use the 3 arg constructor instead. see `https://developer.android.com/reference/com/google/android/material/textview/MaterialTextView#MaterialTextView(Context,AttributeSet,int)`

## Public methods

### setTextAppearance

```
public void setTextAppearance(Context context, int resId)
```