Font size of TextView in Android application changes on changing font size from native settings

前端 未结 14 2110
抹茶落季
抹茶落季 2020-12-04 07:47

I want to specify my own text size in my application, but I am having a problem doing this.

When I change the font size in the device settings, the font size of my

14条回答
  •  借酒劲吻你
    2020-12-04 08:31

    It is not a good thing to have to specify DIP or SP again by code when already defined in a dimen.xml file.

    I think that the best option is to use PX when using a dimen.xml value :

    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.txt_size));
    

    This way, you can switch from DP to SP if needed in dimen.xml file without having to change any code.

提交回复
热议问题