How to change the Font Size in a whole Application programmatically, Android?

后端 未结 6 1468
迷失自我
迷失自我 2020-11-29 05:49

I have created Spinner with the list of Font Sizes from \"8\" to \"46\" . I could be able to click the font Size and in a spinner it has shown me .

My need is, if i

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 06:37

    you can scale to text size of your app up/down using base activity Configuration, make all activities inherent base activity.

    Scale normal value is 1.0, 2.0 would double the font size and .50 would make it half.

    public  void adjustFontScale( Configuration configuration,float scale) {
    
        configuration.fontScale = scale;
        DisplayMetrics metrics = getResources().getDisplayMetrics();
        WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        wm.getDefaultDisplay().getMetrics(metrics);
        metrics.scaledDensity = configuration.fontScale * metrics.density;
        getBaseContext().getResources().updateConfiguration(configuration, metrics);
    
    }
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        adjustFontScale( getResources().getConfiguration());
    }
    

提交回复
热议问题