资源字符串中的换行符不起作用

The*_*ras 2 android textview android-resources

这个问题存在两次:

换行符 \n 不起作用,它显示为字符串

字符串资源换行 /n 不可能吗?

但是 \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" />
Run Code Online (Sandbox Code Playgroud)

我如何设置文本:

this.textView.setText(R.string.give_sex_age);
Run Code Online (Sandbox Code Playgroud)

资源中的字符串:

<string name="give_sex_age">You are a new user.\nPlease give your sex and your age</string>
Run Code Online (Sandbox Code Playgroud)

The*_*ras 5

正如 sawing.amusing 在评论中所说,这是 inputType 导致换行符被忽略的原因。我只是删除这一行

android:inputType="textPersonName"
Run Code Online (Sandbox Code Playgroud)

现在可以了!