how to prevent system font-size changing effects to android application?

后端 未结 8 2205
执笔经年
执笔经年 2020-11-27 03:49

I recently finished developing my android application. I used sp (Scaled pixels) for all textSize. The problem is when i adjusted the system font-size, my application\'s fon

8条回答
  •  抹茶落季
    2020-11-27 04:01

    There's another way to prevent app layout issue / font issue from the setting font size change. You can try

    // ignore the font scale here
    final Configuration newConfiguration = new Configuration(
        newBase.getResources().getConfiguration()
    );
    
    newConfiguration.fontScale = 1.0f;
    applyOverrideConfiguration(newConfiguration);
    

    where newBase is from attachBaseContext function. You need to override this callback in your Activity.

    But, the side effect is that if you wanna use animation (objectanimator/valueanimator), then it will cause the weird behavior.

提交回复
热议问题