XML中的TextView字符在预览和实际设备上未正确显示。

huangapple go评论60阅读模式
英文:

TextView characters in XML are not showing properly in preview and real device

问题

我正在开始进行Android应用程序开发,尝试编写我的第一个Android应用程序,但是我在TextView中遇到了一个字符串的问题。
问题是,我尝试在我的应用程序中使用一些特殊字符(如“µ”符号)和“/”,但是XML不识别这些符号,并在预览或在真机运行时将它们替换为“DEMO CASE”。

在xml预览中的结果

我尝试了这些代码 ⁄⁄ 代表“/”,以及 µµ 代表“µ”,但仍然存在相同的问题。

英文:

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>

Result in xml preview

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,然后选择此选项:

XML中的TextView字符在预览和实际设备上未正确显示。

英文:

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:

XML中的TextView字符在预览和实际设备上未正确显示。

huangapple
  • 本文由 发表于 2023年5月29日 17:42:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76356250.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定