我正在尝试正确使用 [CDATA[]]>,因为我想在我的 Activity 中包含 URLS,但它没有显示在我的应用程序中,我也不知道为什么。
谁能告诉我我做错了什么?我还需要在 .java 文件中添加一些东西吗?
这是输出的图片
string.xml
<string name="about_body"><![CDATA[
<b>Dipolog TourGuide and TranslatorApp</b><br>
Author: <b><a href="https://www.facebook.com/tomstorey66">Thomas Storey</a></b><br>
<br>
Thesis Team : <b>Thomas Storey, Christian Acalain, Mary Grace Lee</b></a><br>
Instructor of ABC: <b>Mr Jay Arr Saile</b></a><br>
<br><br>
<b>Many thanks for code and ideas to:</b><br>
This application was made for Thesis Studies II under there instructor Mr Jay Arr Saile during the school year of 2015-2016<br><br>
Dipolog Tour Guide and Translator was made for tourists who are visiting or planning to visit Dipolog
<br><br>
Many thanks for code and ideas to:
<b><a href="https://www.sourcecodester.com>SourceCodester</a></b><br>
<i>Established 2003-Present</i><br><br>
<b><a href="https://www.googleplay.com>Googleplay</a></b><br>
<i>Established 1999-Present</i><br><br>
<b><a href="www.stackoverflow.com>Stack Overflow</a></b><br>
<i>Forum members assisting in debugging
Est 2005-Present</i><br><br>
Google, Google Play and the Google Maps logo are registered trademarks of Google Inc.
]]></string>
content5.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="learn.navdrawbase.MyAbout"
tools:showIn="@layout/my_about">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView android:id="@+id/title_about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:textSize="24sp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp" />
<ScrollView android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="@+id/about_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="14sp" />
</ScrollView>
</LinearLayout>
</RelativeLayout>
MyAbout.java
public class MyAbout extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_about);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "About", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
//Set nav drawer selected to second item in list
mNavigationView.getMenu().getItem(4).setChecked(true);
}
((TextView) findViewById(R.id.about_body)).setText(Html.fromHtml(getString(R.string.about_body)));
最佳答案
将线性布局更改为相对布局内的下方
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/title_about"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:textSize="24sp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/about_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:text="@string/about_body"
android:textSize="14sp" />
</ScrollView>
</LinearLayout>
之后在 onCreate
Activity 中设置文本((TextView) findViewById(R.id.about_body)).setText(Html.fromHtml(getString(R.string.about_body)));
已编辑
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_about);
/**
* YOUR OTHER CODE
*
* */
((TextView) findViewById(R.id.about_body)).setText(Html.fromHtml(getString(R.string.about_body)));
}
关于java - 如何正确使用CDATA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35052548/