资源字符串中的换行符不起作用
Line break in resources strings doesn't work
这个问题存在两次:
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>
正如 seeming.amusing 在评论中所说,输入类型是忽略换行符的原因。我只是删除了这一行
android:inputType="textPersonName"
现在可以了!
这个问题存在两次:
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>
正如 seeming.amusing 在评论中所说,输入类型是忽略换行符的原因。我只是删除了这一行
android:inputType="textPersonName"
现在可以了!