AlertDialogのビューをカスタマイズしたい場合には、ビルダーのsetViewメソッドを使用します。文字フォントくらい簡単にいじれてもいいかなと思うのですが、現状この方法だけのようです。
import android.app.Activity;
import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
public class MyClass extends Activity{
public void myMethod(){
// xmlからダイアログのレイアウトを読み込む
LayoutInflater factory = LayoutInflater.from(this);
LinearLayout layout = (LinearLayout)factory.inflate(R.layout.dialog,null);
// 動的にダイアログのレイアウトを生成する場合
// LinearLayout layout = new LinearLayout(this);
// layout.addView(new Button(this));
AlertDialog.Builder bldr = new AlertDialog.Builder(this);
bldr.setView(layout);
bldr.show();
}
}
参考: ダイアログのボタンイベント
参考: ダイアログのキャンセル・閉じる


コメント