5

2つの質問があります

1)警告ダイアログにスタイルやフォーマットを適用する方法を知っている人はいますか。私は現在、メソッドをBuilder builder = new AlertDialog.Builder(this);使用してコンテンツを設定しています。setMessage()

2) また、linkify によって作成されたリンクの色を変更する方法を知りたいです。デフォルトの青色は必要ありません。

4

2 に答える 2

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);

指定したレイアウトに必要なすべてのフォーマットとスタイルを定義します。

膨張したビューを使用して、レイアウトで定義された特定のテキストビューにアクセスできます。

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他のメソッドから呼び出している場合は、コンテキスト オブジェクトに置き換えます。

于 2010-12-27T18:40:30.973 に答える
3

次のコードを使用して、デフォルトの alertDialog から TextView を抽出することにより、書体とテキストの色を変更できます。

TextView txtAlertMsg = (TextView)alert.findViewById(android.R.id.message);
txtAlertMsg.setGravity(Gravity.CENTER);
于 2011-12-19T12:32:09.067 に答える