MaterialTextView

public class 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.

Summary

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
)

This method is deprecated.

Since AppCompatTextView does not provide a 4 arg constructor, the defStyleRes argument will be ignored.

Public methods

void
setTextAppearance(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(
    Context context,
    AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)

Public methods

setTextAppearance

public void setTextAppearance(Context context, int resId)