0

I need to use the following attribute in several TextViews, where can I store it so that when the value changes they are all changed?

 android:textSize="12sp"

I have the resource files themes.xml and strings.xml, I want to do the same but for the text size

1 Answers1

0

This can be achieved with the help of themes. In your values res folder create some file, for instance, size.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item name="my_text_size" type="dimen">12sp</item>
</resources>

Then, in your values/styles.xml create new theme:

<style name="MyTextView" parent="@style/Widget.AppCompat.TextView">
    <item name="android:textSize">@dimen/my_text_size</item>
</style>

Then, apply your new style to your TextView widgets:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/MyTextView"
            android:text="HELLO1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            style="@style/MyTextView"
            android:text="HELLO2"/>
</LinearLayout>