【发布时间】:2021-09-16 12:10:51
【问题描述】:
string.xml 这是我的字符串
<string name="bullet_text"><font color="#38d98a">●</font>\t\tCucumber Detox Water (1 glass)\n<font color="#38d98a">●</font>\t\tSkimmed Milk (1 glass)\n<font color="#38d98a">●</font>\t\tPeas Poha (1.5 katori)</string>
当这个字符串在 xml 中使用时它工作得很好,但是当以编程方式使用这个字符串时它就不起作用了
xml 代码
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/bullet_text"
android:textSize="20sp"
android:layout_margin="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
完美运行
Kotlin 代码
val textView:TextView = findViewById(R.id.textView)
textView.text = getString(R.string.bullet_text)
工作不完美
【问题讨论】:
-
试试Like This。
-
它可以工作,但字符串中的 \n 不工作
-
现在可以了,我将 \n 替换为
标签: android string android-studio textview