2011年2月26日土曜日

Android Dialog のタイトル部分をなくす

Dialog クラスのインスタンスを生成して、ダイアログを作った場合


ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.bg);

Dialog dialog = new Dialog(this);
dialog.setContentView(imageView);
dialog.show();


setTitle() でタイトルを設定しなくてもタイトル部分が表示されてしまいます。



ちなみに、ProgressDialog の場合は、setTitle() を呼ばなければタイトル部分は表示されません。

Dialog でタイトル部分を消すには、requestWindowFeature() で Window.FEATURE_NO_TITLE を指定します。


ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.bg);

Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(imageView);
dialog.show();


requestWindowFeature() は setContentView() より前に呼ぶ必要があります。

1 件のコメント:

  1. Mayと申します。いつも大変参考にさせていただいております。ProgressDialogでテーマを設定した場合(windowBackground有り)、setTitleしなくてもタイトル部分が表示されてしまいます。解決方法をご存じでしたらご教授戴ければ幸いです。

    返信削除