2021-04-22 ReactNative 修改手机字体字号 Text 变化的问题

如果是在Android的设备中需要添加以下代码:

import android.content.res.Configuration;
import android.content.res.Resources;
public class MainActivity extends ReactActivity {
...
// 禁止字体缩放
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config=new Configuration();
config.setToDefaults();
res.updateConfiguration(config,res.getDisplayMetrics());
return res;
}
}

 

可以写到自己的基类中去。

iOS

使用Text 的一个属性 allowFontScaling={false}

提供一个通用的方法在RN里

在项目写global变量的地方加入:

import { Text, TextInput } from 'react-native'

TextInput.defaultProps = Object.assign({}, TextInput.defaultProps, {allowFontScaling: false}); // 新版RN使用该方法替代
Text.defaultProps = Object.assign({}, Text.defaultProps, {allowFontScaling: false});

 

上面修改了全局的Text 、TextInput的allowFontScaling默认值,如果项目使用了react-navigation,还需要修改 headerTitleAllowFontScaling = false参考API
如果引入了react-native-flux-router ,在Tab 节点,加入allowFontScaling={false} 属性,屏蔽掉导航栏和TabBar上的字体变大
<Tabs key="root" allowFontScaling={false} ......>


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序邦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值