所以我现在完全迷路了,当用户通过Accessibility -> Font size 将字体大小时设置为Huge 时,文本大小会破坏我的 UI,所以为了快速修复 我决定将所有文本大小更改为 dp 而不是 sp 文本将始终具有相同的大小,但在某些地方 textviews 即使 textsize 设置为 dp 调整大小知道为什么吗??
这是文本大小设置为 dp 的按钮,即使在通过辅助功能更改后也能保持字体大小
<Button
android:id="@+id/video_button"
android:textSize="16dp"
android:layout_marginTop="10dp"
android:layout_height="30dp"
android:layout_width="180dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/webshop_button"
android:text="@string/button_3dvideo_text"/>
这里是 textView,即使在将其设置为 dp 后也会忽略 textSize:
<TextView
android:id="@+id/about"
android:gravity="center"
android:textSize="16dp"
android:layout_above="@+id/footer"
android:layout_marginBottom="20dp"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/color_white"
android:text="@string/about"/>
最佳答案
我有一个解决方案,可以使您的应用程序中的字体大小不可更改:
public void adjustFontScale(Configuration configuration) {
configuration.fontScale = (float) 1;
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);
}
在每个 Activity 的 onCreate 中调用此方法,或者您可以创建一个 Base Activity:
adjustFontScale(getResources().getConfiguration());
您可以根据需要更改 fontScale。 希望这会有所帮助。
关于android - 文本大小(dp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47261909/