Alexander Ignácz Alexander Ignácz - 1 month ago 18
Android Question

Android: AppCompatTextView custom style

I'm going to set default style for AppCompatTextView through whole application including

android:textColor
,
android:maxLines
, and
android:inputType
.

I found that I can set default style for AppCompatEditText by following codes.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!--EditText Style-->
<item name="editTextStyle">@style/My_EditTextStyle</item>
</style>

<style name="My_EditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:maxLines">1</item>
<item name="android:inputType">text</item>
...
</style>


So what would be the item name for
AppCompatTextView
like
"editTextStyle"
here? I tried with
"textViewStyle"
but it doesn't work.

Answer Source
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:editTextStyle">@style/My_EditTextStyle</item>
        <item name="editTextStyle">@style/My_EditTextStyle</item>
        <item name="android:textViewStyle">@style/My_TextViewStyle</item>
        <item name="textViewStyle">@style/My_TextViewStyle</item>
    </style>

    <style name="My_EditTextStyle" parent="@android:style/Widget.EditText">
        <item name="android:maxLines">1</item>
        <item name="android:inputType">text</item>
        ...
    </style>    

    <style name="My_TextViewStyle" parent="@android:style/Widget.TextView">
        <item name="android:maxLines">1</item>
        <item name="android:inputType">text</item>
        ...
    </style>