Device settings independent font size

前端 未结 3 1445
南旧
南旧 2021-01-21 04:11

While developing my app I realised if someone changes device font size from normal, my application font sizes change too and it destroys some of the visuals I designed. So I wan

3条回答
  •  余生分开走
    2021-01-21 05:12

    check the source code DisplaySettings.java, here is the method to control font size scale

    public void writeFontSizePreference(Object objValue) {
        try {
            mCurConfig.fontScale = Float.parseFloat(objValue.toString());
            ActivityManagerNative.getDefault().updatePersistentConfiguration(mCurConfig);
        } catch (RemoteException e) {
            Log.w(TAG, "Unable to save font size");
        }
    }
    

    here is a solution keep the font size in different fontscale.

    float textSize = 22f;
    mTextView.setTextSize(textSize / getResources().getConfiguration().fontScale);
    

    and I think @shoe rat's answer is more better for an activity or application context.

提交回复
热议问题