Parent style for TextView style with AppCompat usage

android textview style example
custom textview style android
android:textappearance
textappearance vs style
how to set text appearance in android xml
android:text style
android:windowbackground
android settextappearance programmatically

What parent style should I use if I want to set global textViewStyle and maintain backward compatibility with AppCompat? I can't find something like Widget.AppCompat.TextView :

<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="android:textViewStyle">@style/GlobalTextViewStyle</item>

</style>

<style name="GlobalTextViewStyle" parent="?????">
    <item name="android:textAppearance">@style/TextAppearance.AppCompat.Medium</item>
</style>

You just need to extend TextAppearance.AppCompat style overriding necessary values:

<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="android:textAppearance">@style/MyTextAppearance</item>

</style>

<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
        <item name="android:textColor">?android:textColorPrimary</item>
        <item name="android:textColorHint">?android:textColorHint</item>
        <item name="android:textColorHighlight">?android:textColorHighlight</item>
        <item name="android:textColorLink">?android:textColorLink</item>
        <item name="android:textSize">@dimen/abc_text_size_body_1_material</item>
        <item name="textColor">?textColorPrimary</item>
        <item name="textColorHighlight">?textColorHighlight</item>
        <item name="textColorHint">?textColorHint</item>
        <item name="textColorLink">?textColorLink</item>
        <item name="textSize">16sp</item>
        <item name="textStyle">normal</item>
</style>

Styles and Themes, By extracting all the attributes to a style, it's easy to use and maintain them across To extend a style, specify the style you want to extend with the parent attribute. have a name similar to the style from the platform, but with AppCompat included. For example, the TextView XML attributes includes the android: inputType� This will automatically be used when you use TextView in your layouts and the top-level activity / dialog is provided by appcompat. You should only need to manually use this class when writing custom views.

<style name="normal_text_white" parent="@android:style/TextAppearance.Medium">
    <item name="android:textColor">@color/white_color</item>
    <item name="android:textSize">@dimen/small_text_size</item>
    <item name="android:textColorHint">@color/hint_color</item>
</style>

Styles and Themes, <TextView android:id="@+id/tv_text" style="@style/LargeRedFont" To reference a built-in style you must use the parent attribute: <style AppCompat. Light"> . There’s a new serif in town! </dad> Let’s say you want all your TextViews to use serif fonts. We can create a bunch of custom text appearances, but there’s a better way to handle this

If you want to set this style for all your TextView's in your app, you can do something like this:

<resources>
<style name="YourTheme" parent="android:YourParentThTheme">
    <item name="android:textViewStyle">@style/GlobalTextViewStyle </item>
</style>

<style name="GlobalTextViewStyle" parent="android:Widget.TextView">
    <item name="android:textColor">#FF000</item>
    <item name="android:textStyle">bold</item>
</style>
</resources>

Android: Working with themes and styles | by Joanne Kao, xml (or styles.xml — whatever your preference). <style name="Theme.Kyoto" parent="Theme.AppCompat.Light.NoActionBar"> Note: If you use the dot notation to extend a style, and you also include the parent attribute, then the parent styles override any styles inheritted through the dot notation. To find which attributes you can declare with an <item> tag, refer to the "XML attributes" table in the various class references.

We can try this as well for AppCompat widget.

<style name="TitleStyle" parent="TextAppearance.AppCompat">
        <item name="android:gravity">center_horizontal</item>
        <item name="android:textColor">@android:color/black</item>
        <item name="android:textSize">26sp</item>
</style>

My experience with Material Design Components on Android, The AppCompat and MaterialComponents design systems (referenced also as theme families) - unlike the Holo system - uses a specific view inflater class ( defined by the TextView" parent="Widget. Helpfully, the style of most components is associated with a theme attribute, like the above for TextView,� If you observe above code snippet, we defined a TextView control with required style attributes directly in XML layout file. Suppose if we use same or similar TextView styles in multiple places of our application, then the duplication of code will increase and in future, if we want to change the style of our application, we need to update the same style in all the places and it’s a time

How to apply global custom style to android.support.design.widget , Parent style for TextView style with AppCompat usage. What parent style should I use if I want to set global textViewStyle and maintain backward compatibility� In XML, you would create a simple text style that sets android:textColorto a color. This style could then be applied to TextViewsin an app, and if the standard text color needed to change, only the

How to Support Themes in Custom Views for Android Apps, <TextView android:id="@+id/description" /> </merge> Note: When you use a custom attribute in style, don't use the android or app prefix. When styling text in Android apps, TextView offers multiple attributes and different ways to apply them. You can set attributes directly in your layout, you can apply a style to a view, or a theme

res/values/styles.xml, background and text color. See also android:style/Widget.Holo.TextView. ListSeparator. (which is private, so we cannot specify it as a parent style). -->. < style� NOTE: This will introduce additional top padding between Spinner and TextView Label. To solve this, remove the TextView’s bottom padding. If you want to change the color of Spinner’s underline, use setBackgroundTintList.

Comments
  • possible duplicate of : stackoverflow.com/questions/3078081/…
  • Did you tried to don't set a parent? Just this: <style name="GlobalTextViewStyle">. Or it's important to set value of parent attribute? I'm having the same problem right now, but there are no any competent decision. I think using android:... as parent is bad if you use AppCompat.
  • I don't know why but it doesn't work. When I use Luiz Fernando Salvaterra solution style is correctly applied to the all textviews.
  • @AppiDevo, that means you should upvote and accepts Luiz's answer.