【问题标题】:React native textDecoration properties not working on Android反应原生 textDecoration 属性在 Android 上不起作用
【发布时间】:2016-03-03 09:23:16
【问题描述】:

我正在使用

<Text style={styles.sampleStyle}> Something </Text>

以下样式:

sampleStyle: {
    textDecorationLine: "underline",
    textDecorationStyle: "solid",
    textDecorationColor: "#000",
}

但是,它们似乎不起作用。我做错了什么?

【问题讨论】:

  • 目前好像只有IOS支持:https://facebook.github.io/react-native/docs/text.html#content你有没有找到其他解决方案或库来解决这个问题?
  • 还没有,抱歉。因为我只需要在一行文本上使用它,所以我用它下面的视图伪造了下划线。

标签: android reactjs react-native


【解决方案1】:

您没有为 Text 组件指定所需的样式。尝试:

<Text style={styles.sampleStyle} >Something </Text>

var styles = StyleSheet.create({
  sampleStyle: {
    textDecorationLine: "underline",
    textDecorationStyle: "solid",
    textDecorationColor: "#000"
  }
});

【讨论】:

  • 对不起,我没有直接复制代码,我只是想演示一下我想要实现的目标。所有其他样式都有效,但装饰无效。
  • textDecorationStyle: "dotted" 不适用于 android
  • textDecorationColor: "#000" 这对我不起作用
【解决方案2】:
<Text style={styles.sampleStyle}>Something</Text>

var styles = StyleSheet.create({
    sampleStyle: {
        color: "#000"
    }
});

一个老问题,但对于那些在 2020+ 年仍在搜索的人来说,这里有一个快速答案

对于 Android,似乎只需要简单地使用 color: 即可。如果您查看文档,则 textDecorationColor 标记为供 ios 使用。 https://reactnative.dev/docs/text-style-props

【讨论】:

  • 如果我希望文本为黑色并用红色删除线,如何在 android 中实现这一点。(它适用于 iOS)
【解决方案3】:
sampleStyle: {
   textDecorationLine: "underline",
   textDecorationStyle: "solid",
   textDecorationColor: "#000",
}

仅适用于 ios

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多