2

このコードでカスタム DialogPreference を作成します。

import android.content.Context;
import android.preference.DialogPreference;
import android.util.AttributeSet;

public class DialogPref extends DialogPreference {

    public DialogPref(Context context, AttributeSet attrs) {
        super(context, attrs);

        setDialogLayoutResource(R.layout.my_dialog);
    }
}

そして、このレイアウトでは:

<?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"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="10dip"
        android:text="@string/dialog_text" />

</LinearLayout>

これをコンパイルすると、有効なダイアログが表示されますが、このダイアログの TextView は暗い背景に黒です。では、Dialog テーマで TextView の色を変更する方法はありますが、レイアウトでは手動では変更できません。ありがとう

4

1 に答える 1