【发布时间】: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