huilo
huilo

Reputation: 47

Override text size of textview

I want to set a text size in UserSetting to my textView programmatically; the problem is when it change with myTextView.setTextSize(18) once i return to my xml it go Back to default size, I don't want that instead i want to keep my own text size.

my TextView xml:

<TextView
                        android:id="@+id/MainText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/spacing_large"
                        android:layout_marginRight="@dimen/spacing_large"
                        android:layout_marginTop="15dp"
                        android:lineSpacingExtra="3dp"
                        android:text="long_lorem_ipsum_2"
                        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                        android:textColor="@color/grey_60"
                        android:layout_marginBottom="80dp"/>

Upvotes: 1

Views: 119

Answers (1)

Amrdroid
Amrdroid

Reputation: 387

use SharedPreferences to save Your Own TextSize

code to save textsize in SharedPreferences:

  SharedPreferences  pref=getSharedPreferences("MyPref",MODE_PRIVATE);              
   SharedPreferences.Editor editor=pref.edit();            
   editor.putFloat(FONT_SIZE_KEY,textSize);    // your textsize       
   editor.commit();

to retreive textsize Value from SharedPreferences

       SharedPreferences prefs=getSharedPreferences("MyPref", MODE_PRIVATE);
       float fontsize=prefs.getFloat(FONT_SIZE_KEY, 12);

Upvotes: 2

Related Questions