android – 如何使用警告对话框生成器在PopUp框中显示Html格式的文本?

我使用 android警告对话框构建器将一些用户消息(String)显示为用户的弹出框.

现在,我的要求是消息框应该能够支持此消息的HTML格式.包括,此用户消息中可能返回了一个URL /链接.选择此链接应将当前应用程序置于后台并弹出手机的浏览器并将用户带到链接中的URL.关闭浏览器会将应用程序带回前台.

我怎样才能做到这一点?我可以使用相同的警报对话框构建器或任何其他可用选项吗?

解决方法

以上所有答案都不会删除html标签之类的,如果给定的字符串包含,我试图删除所有标签,这对我来说工作正常
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Title");

LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,null);

TextView text = (TextView) layout.findViewById(R.id.text);
text.setMovementMethod(LinkMovementMethod.getInstance());
text.setText(Html.fromHtml("<b>Hello World</b> This is a test of the URL <a href=http://www.example.com> Example</a><p><b>This text is bold</b></p><p><em>This text is emphasized</em></p><p><code>This is computer output</code></p><p>This is<sub> subscript</sub> and <sup>superscript</sup></p>";));
builder.setView(layout);
AlertDialog alert = builder.show();

和custom_dialog会是这样的;

<TextView android:id="@+id/text"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          android:textColor="#FFF"
          />

上面的代码将删除所有的html标记,并在指定的html格式文本中显示Example as Click able URL.

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...