我有两个问题
1)有谁知道,如何将样式或格式应用于警报对话框。我目前使用Builder builder = new AlertDialog.Builder(this);
And usesetMessage()
方法来设置内容。
2)我也想知道如何改变由linkify创建的链接的颜色。我不想要默认的蓝色。
我有两个问题
1)有谁知道,如何将样式或格式应用于警报对话框。我目前使用Builder builder = new AlertDialog.Builder(this);
And usesetMessage()
方法来设置内容。
2)我也想知道如何改变由linkify创建的链接的颜色。我不想要默认的蓝色。
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);
定义您指定的布局中所需的所有格式和样式。
您可以使用膨胀视图访问布局中定义的特定文本视图,即
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);
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>
在您的 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);
this
如果您从其他方法调用,请替换为上下文对象。
您可以使用以下代码通过从默认 alertDialog 中提取 TextView 来更改字体和文本颜色:
TextView txtAlertMsg = (TextView)alert.findViewById(android.R.id.message);
txtAlertMsg.setGravity(Gravity.CENTER);