MaterialTextView

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.

For more information, see the component developer guidance.

Constructors

Link copied to clipboard
constructor(@NonNull context: Context)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int)
constructor(@NonNull context: Context, @Nullable attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int)

Functions

Link copied to clipboard
open fun setTextAppearance(@NonNull context: Context, resId: Int)