React-native textAlign 对齐

React-native textAlign justify

Android

我尝试使用 textAlign 使文本对齐,但它不起作用。

<Text style={{textAlign: 'justify',color:'#1B3D6C', margin: 20}}>
Lorem ipsum dolor sit amet, et usu congue vocibus, ei sea alienum repudiandae, intellegam quaerendum an nam. Vocibus apeirian no vis, eos cu conguemoo scaevola accusamus. Et sea placerat persecutii oinn
</Text>

编辑: 好的,textAlign justify 在 Android 上不起作用,所以我现在问的是是否有解决方案?我真的需要!

Android 不支持文本对齐。 React Native Text component 关于 style 属性的文档说:

textAlign enum('auto', 'left', 'right', 'center', 'justify') : Specifies text alignment. The value 'justify' is only supported on iOS and fallbacks to left on Android.

此限制的解决方法是使用 React Native WebView 组件。 WebView 的内容可以是带有对齐文本的 HTML 代码。像这样:

<View style={{flex: 1}}>
    <WebView
        source={{ html: "<p style='text-align: justify;'>Justified text here</p>" }}
    />
</View>

** 更新 **

对于旧版本的react-native,textAlign:'justify'不适用于android,但现在它支持textAlign:'justify' android奥利奥及以上

textAlign: enum('auto', 'left', 'right', 'center', 'justify')

指定文本对齐方式。值 'justify' 仅在 iOS 和 Android Oreo (8.0) 或更高版本(API 级别 >= 26) 上受支持。对于较低的 android 版本,它将退回到左侧。