Android:警报对话框中的格式字体

Viv*_*vek 5 android dialog linkify android-alertdialog

我有两个问题

1)有谁知道,如何应用样式或格式来警告对话框.我目前使用Builder builder = new AlertDialog.Builder(this);And use setMessage()方法设置内容.

2)另外我想知道如何更改linkify创建的链接的颜色.我不想要默认的蓝色.

Sha*_*dul 12

Q1.您必须膨胀或自定义并创建样式并应用于AlertDialog

下面是如何夸大布局并将其应用于AlertDialog

LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);

AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle("Formatted");
builder.setView(view);
Run Code Online (Sandbox Code Playgroud)

定义您指定的布局中所需的所有格式和样式.

您可以使用膨胀的视图访问布局中定义的特定textview

LayoutInflater li = LayoutInflater.from(ctx);
View view = li.inflate(R.layout.formatted_dialog, null);
TextView label=(TextView)view.findViewById(R.id.i_am_from_formatted_layout_lable);
Run Code Online (Sandbox Code Playgroud)

Q2.android:textColorLink="#FF00FF"可用于指定链接的颜色.

编辑:

样本布局保存为res/layout/link.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <TextView
   android:id="@+id/text"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="http://www.google.com"
   android:autoLink="web"
   android:textColorLink="#FF00FF"
  />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

在你的onCreate()或你想要调用AlertDialog的地方或任何地方

LayoutInflater li = LayoutInflater.from(this);
View view = li.inflate(R.layout.link, null);

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Formatted");
builder.setView(view).create().show();
TextView text=(TextView) findViewById(R.id.text);
Run Code Online (Sandbox Code Playgroud)

this如果从其他方法调用,则替换为上下文对象.