英文:
TextView characters in XML are not showing properly in preview and real device
问题
我正在开始进行Android应用程序开发,尝试编写我的第一个Android应用程序,但是我在TextView中遇到了一个字符串的问题。
问题是,我尝试在我的应用程序中使用一些特殊字符(如“µ”符号)和“/”,但是XML不识别这些符号,并在预览或在真机运行时将它们替换为“DEMO CASE”。
我尝试了这些代码 ⁄
和 ⁄
代表“/”,以及 µ
和 µ
代表“µ”,但仍然存在相同的问题。
英文:
I'm starting the Android app development and I'm trying to code my first app in Android, however I am encountering a problem with Strings in TextView.
The problem is that I am trying to use some special characters for my app (like "µ" sign) and "/" but the xml does not recognize those signs and replace them with "DEMO CASE" either in preview or during runtime on a real device.
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/ti_layout_aceta"
style="@style/ThemeOverlay.Material3.TextInputEditText.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
app:endIconMode="clear_text"
app:layout_constraintEnd_toStartOf="@id/gl_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cv_a_header">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_unit1_aceta"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/hint"
android:inputType="numberDecimal" />
</com.google.android.material.textfield.TextInputLayout>
I tried those codes ⁄ ⁄ for "/" and µ µ for "µ" but still have the same problem.
答案1
得分: 0
以下是要翻译的内容:
在XML文本中,某些特殊字符可能无法正确支持。您可以将它们包装在CDATA
块中:
<string name="hint"><![CDATA[µ]]></string>
在Android Studio中,有一种简单的方法可以做到这一点。将光标置于文本内部,按下Alt+Enter
,然后选择此选项:
英文:
Some special characters aren't properly supported in XML texts. You can wrap them in a CDATA
block:
<string name="hint"><![CDATA[µ]]></string>
There is an easy was to do this in Android Studio. Put your cursor inside the text, press Alt+Enter
and select this option:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论