【问题标题】:Line break in resources strings doesn't work资源字符串中的换行不起作用
【发布时间】:2019-04-22 03:48:22
【问题描述】:

这个问题存在两次:

Line break \n doesn't work, it show as string

String Resource new line /n not possible?

但是\n 或在strings.xml 中按回车键都没有给我设置文本的textView 中的换行符。 有谁知道为什么?

我的文本视图:

   <TextView
    android:id="@+id/textView"
    android:layout_width="952dp"
    android:layout_height="172dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="@string/give_username"
    android:textSize="45sp"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.003" />

我如何设置文本:

this.textView.setText(R.string.give_sex_age);

资源中的字符串:

<string name="give_sex_age">You are a new user.\nPlease give your sex and your age</string>

【问题讨论】:

  • 如果您的 TextView 的 inputType 设置为“文本”,这可能是忽略换行符的原因。话虽如此,更多信息(例如,具体示例)将有助于给出具体答案。
  • "但是在 strings.xml 中的 \n 或回车都没有给我换行"....给个示例
  • 我更新了问题
  • @seeming.amusing 删除 inputType 并且它可以工作。谢谢!

标签: android textview android-resources


【解决方案1】:

就像在 cmets 中说的那样,inputType 是忽略换行符的原因。我只是删除了这一行

android:inputType="textPersonName"

现在可以了!

【讨论】:

  • 为什么 TextView 会有一个 inputType?
  • @MartyMiller 那是个错误。 TextView 不能有 inputType。但谷歌出于某种原因允许此字段
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多