【问题标题】:XML code in TextView to make a learning appTextView 中的 XML 代码制作学习应用程序
【发布时间】:2019-07-23 20:26:37
【问题描述】:

我正在为学习 Android 的初学者开发一个 android 应用程序我已经开发了大部分应用程序,但现在当我尝试将 XML 代码粘贴到文本视图中时,Android Studio 显示错误(我希望在 TextView 中显示该代码)。

我没有得到太多帮助,但我尝试使用资源>值>字符串并尝试将代码粘贴到文本字段中。我该如何解决它

<resources>
<string name="textviewcode">Learn Android</string>


 I changed the text(Learn Android) with code and now the app is not working


<string name="textviewcode"><RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

   <TextView
   android:id="@+id/text_id"
   android:layout_width="300dp"
   android:layout_height="200dp"
   android:capitalize="characters"
   android:text="hello_world"
   android:textColor="@android:color/holo_blue_dark"
   android:textColorHighlight="@android:color/primary_text_dark"
   android:layout_centerVertical="true"
   android:layout_alignParentEnd="true"
   android:textSize="50dp"/>

</RelativeLayout></string>
</resources>

【问题讨论】:

  • 您想帮助他人,但在基本问题上遇到问题?为了帮助您解决问题,it is not allowing me to paste XML code in text view 是什么意思。谁是“它”,你看到一些错误吗?另外,请阅读stackoverflow.com/help/how-to-ask
  • 这是我第一个练习android的项目
  • 它说什么?可能您需要转义特殊字符,例如&gt;
  • 显然是 AS。当我粘贴代码时它显示错误
  • @VladyslavMatviienko 与元素类型“ListView”关联的属性“android:id”的前缀“android”未绑定。只是因为我粘贴了 xml 代码

标签: android


【解决方案1】:

您需要使用 CDATA 块转义您的 textviewcode

例子:

<string name="textviewcode"><![CDATA[YourCodeGoesHere]]></string>

此块允许您在值中使用 &lt;' 等符号而不会破坏

【讨论】:

  • 我未能以正确的方式提出问题,但它有效
猜你喜欢
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 2018-04-25
  • 1970-01-01
  • 2010-10-10
  • 2011-05-05
  • 2017-09-19
  • 1970-01-01
相关资源
最近更新 更多