android设置:调整字体大小

android设置:调整字体大小,android,fonts,font-size,Android,Fonts,Font Size,在手机设置中,我可以全局更改应用程序的字体大小 设置>显示>字体大小 我是否可以使用Java阅读字体大小(小、普通、大、非常大),如果适用的话。仅为我的应用程序设置? 我试图改变字体大小如下 Button buttonbig = (Button) dialog.findViewById(R.id.btn_big); buttonbig.setOnClickListener(new OnClickListener() { public void onClick(View v

在手机设置中,我可以全局更改应用程序的字体大小

设置>显示>字体大小

我是否可以使用Java阅读字体大小(小、普通、大、非常大),如果适用的话。仅为我的应用程序设置? 我试图改变字体大小如下

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();

我的文本视图显示了新的大小。但是,文本大小保持不变。有人知道怎么回事吗?

首先,我强烈建议不要覆盖语言、字体大小或其他设置,因为正如您所指出的,这是您应该在全局范围内执行的操作

如果您想为整个应用程序设置它,正确的位置应该是在
应用程序中

public class App extends Application {

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

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

如果您想在运行时更改它,您也可以在应用程序中设置它,但您必须完成并再次启动活动才能生效。

如果您只想更改此textView的字体大小,试试看如何

 textView.setTextSize(float);

可能存在的副本