我试图使用[CDATA []]>正确的,因为我想在我的活动中包含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)));
答案 0 :(得分:2)
将线性布局更改为相对布局内的
public static class Reduce extends Reducer<Text,Text,NullWritable,Text>{
public void reduce(NullWritable key, Iterable<Text> values, Context context) throws IOException, InterruptedException{
try{
for(Text val : values){
context.write(key, new Text(val.toString()));
}
}catch(JSONException e){
e.printStackTrace();
}
}
}
之后在活动 onCreate
中设置文字<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>
<强> EDITED 强>
((TextView) findViewById(R.id.about_body)).setText(Html.fromHtml(getString(R.string.about_body)));
答案 1 :(得分:1)
是的,你必须给文本属性提供String引用。使用+ id,您可以在R文件中创建新ID。
您可以直接获得该html文本代码,也可以看到以下链接,您可以从中获得想法
Android TextView supported Html Tags
第二件事就是你错过了一些关闭的标签,看看锚标签你没有把它放在那里
答案 2 :(得分:0)
您正在使用字符串的ID,但您需要使用实际字符串,即@ string / about_body而不是@ + id / about_body。其余的看起来是正确的。