【问题标题】:react native prop allowFontScaling not working on android反应原生道具allowFontScaling在android上不起作用
【发布时间】:2018-09-11 12:27:42
【问题描述】:

我是 react-native 的新手,如果我从设备设置中增加文本大小,我想修复应用程序所有屏幕中的文本大小,那么我尝试过的字体大小也应该相同:

Text.defaultProps.allowFontScaling=false;

在 android.index.js 中 和

public void adjustFontScale(Context context, Configuration configuration) {
    configuration.fontScale =(float) 0.85;
    DisplayMetrics metrics = context.getResources().getDisplayMetrics();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getMetrics(metrics);
    metrics.scaledDensity = configuration.fontScale * metrics.density;
    context.getResources().updateConfiguration(configuration, metrics);

}

super.onCreate(); 之后在oncreate() 中调用的mainactivity.js 中

从 AndroidManifest.xml 链接的自定义主题也不起作用

如果有人对此有其他解决方案,请帮助我。

它在 ios 设备上完美运行。

【问题讨论】:

    标签: android react-native android-layout android-activity react-redux


    【解决方案1】:

    (应该是评论,但我没有代表!)

    似乎是字体缩放的一些错误,请在此处查看一些问题:

    https://github.com/facebook/react-native/issues/18827

    有人cmet:

    同样在 React Native 0.56.0 中设置 TextInput.defaultProps.allowFontScaling = false;根本不起作用。

    有人为此问题创建了一个库,但是我没有对此进行测试:

    https://github.com/NelGarbuzova/react-native-stylized-placeholder

    更新:我已经在我的 Android 模拟器上进行了测试,它的工作原理如下:

    "react": "16.3.0-alpha.0",
    "react-native": "0.55.0",
    
    
    public render() {
        return (
            <View>
                <Text allowFontScaling={false}>Text Scaling</Text>
                <Text>No Text Scaling</Text> 
            </View>
        )
    }
    

    结果低于像素 2(运行 28)

    【讨论】:

    • 仍然没有修复。
    • 你使用的是什么版本的 React Native?稍后我会在我的安卓设备上试一试
    • 我使用的RN版本是0.55,我也试过0.56
    • 你试过图书馆了吗?
    • 我今天给你试一试。
    猜你喜欢
    • 2021-07-05
    • 2016-03-03
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 2019-09-13
    相关资源
    最近更新 更多