MaterialTextView


Kotlin |Java

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:

publicclassMainActivityextendsActivity{
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
finalMaterialTextViewtextView=(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)

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2026年05月14日 UTC.