6

アラートダイアログの明るい背景に暗い色でテキストを表示したい。しかし、私はこれを行う方法を理解することはできません。私を助けてください。

ありがとう。

4

2 に答える 2

7

アクティビティの場合と同じように、XML ビューで独自のレイアウトを作成できます。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>

setContentView(View)次に、ダイアログを呼び出して、ダイアログでこのビューを使用できます。

Context mContext = getApplicationContext();
Dialog dialog = new Dialog(mContext);

dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("Custom Dialog");

TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

例が示すように、コンテンツ ビューを宣言した後、いくつかの値を設定する必要があります。

http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialogから提供される例

于 2011-01-24T13:33:48.600 に答える
6

この例を参照してください。


警告ダイアログのファイルで定義されたこの例のレイアウトのように、警告ダイアログのスタイルを設定できます。

于 2011-01-24T13:30:50.920 に答える