-1

In the settings in my phone can I change the font size of apps globally .

Settings> Display> Font size

Can I make the font size (small, normal, large , very large ) also read with Java and, if applicable . set only for my app ? I tried to change the font size as follows.

Button buttonbig = (Button) dialog.findViewById(R.id.btn_big);
    buttonbig.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            float fScale = getResources().getConfiguration().fontScale;
            String fontSize = String.valueOf(fScale);


            conf.fontScale =fScale + 0.15f;
            getResources().getConfiguration().setTo(conf);

            TextView textView = (TextView) dialog.findViewById(R.id.lbl_size_act);
            textView.setText(fontSize);


        }
    });
    dialog.show();

My Text View shows me the new size . However, the text remains the same size .Have anyone an idea what's wrong ?

2 Answers2

0

First of all, I strongly advise against overriding the language, font size, or other settings, because as you pointed out, this is something you should do globally.

If you want to set it for your whole app, the right place to do so would be in the Application.

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Configuration configuration = getResources().getConfiguration();
        configuration.fontScale *= 2;
        getResources().updateConfiguration(configuration, getResources().getDisplayMetrics());
    }
}

If you want to change it during runtime, you would also set it in application, but you would have to finish and start your activity again to take effect.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134
0

If you want to change only this textView's font size, how about trying

 textView.setTextSize(float);

http://developer.android.com/reference/android/widget/TextView.html#setTextSize(float)

pleft
  • 7,567
  • 2
  • 21
  • 45