基本上,我使用 Html.fromHtml 方法在 textView 中以 html 格式显示文本。一切都正确呈现,除了列表项的项目符号。就像这种情况一样,它们被切断(textview 中的项目符号被切断)。
我在这里看到的(textview 中的项目符号点被切断)和这里(https://medium.com/ackee/how-to-make-bulletproof-bullet-lists-in-textview-223c54fb21e6),表明 BulletSpan类有一些错误,所以在以后的版本(API lvl 28)中他们修复了它。但是,在我尝试过的所有事情中,我目前有: + API lvl 28 安装 + 在 gradle 中编译和目标 sdk 版本 --> 28 + gradle 中的 min sdk 版本 --> 24 + 具有 android 7.0 的设备(意思是:API lvl24)
它仍然显示子弹被切断
主要布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:id="@+id/basicTextView"
android:layout_width="300dp"
android:layout_height="400dp"
android:text="Hello World!"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
主要活动java代码:
import android.app.Dialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import static android.text.Html.FROM_HTML_MODE_LEGACY;
public class MainActivity extends AppCompatActivity {
private TextView textview, basicTextView;
private Button confirmButton;
private String text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
basicTextView = (TextView) findViewById(R.id.basicTextView);
text = "<ul>\n" +
" <li>Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.</li>\n" +
" <li>Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.</li>\n" +
" <li>Phasellus ultrices nulla quis nibh. Quisque a lectus. Donec consectetuer ligula vulputate sem tristique cursus. Nam nulla quam, gravida non, commodo a, sodales sit amet, nisi.</li>\n" +
" <li>Pellentesque fermentum dolor. Aliquam quam lectus, facilisis auctor, ultrices ut, elementum vulputate, nunc.</li>\n" +
"</ul>" +
"<nav>\n" +
" <ul>\n" +
" <li><a href=\"#\">Home</a></li>\n" +
" <li><a href=\"#\">About</a></li>\n" +
" <li><a href=\"#\">Clients</a></li>\n" +
" <li><a href=\"#\">Contact Us</a></li>\n" +
" </ul>\n" +
"</nav>" +
"<h1>Main Title</h1>\n" +
" <h2>A sub-title</h2>\n" +
" <p>This is some html. Look, here\\'s an <u>underline</u>.</p>\n" +
" <p>Look, this is <em>emphasized.</em> And here\\'s some <b>bold</b>.</p>\n" +
" <p>This is a UL list:\n" +
" <ul>\n" +
" <li>One</li>\n" +
" <li>Two</li>\n" +
" <li>Three</li>\n" +
" </ul>\n" +
" <p>This is an OL list:\n" +
" <ol>\n" +
" <li>One</li>\n" +
" <li>Two</li>\n" +
" <li>Three</li>\n" +
" </ol>";
basicTextView.setText(Html.fromHtml(text, FROM_HTML_MODE_LEGACY));
}
}
因此,即使它应该正确呈现列表项目符号,它仍然没有。我在 Android Studio 中安装了正确的 API lvl,所以我不知道应该如何解决这个问题。如果有不清楚的地方请询问。有任何想法吗?