カスタム レイアウト用の別の XML ファイルを用意せずに、ダイアログ フラグメントのメッセージに重心を追加しようとしています。TextView を取得してその重力を設定しようとしましたが、何もしないようです:
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Replace current sound");
builder.setMessage("Choose a mp3 or ogg file or restore the default sound.\nThe current sound is:\n"+currentSound)
.setPositiveButton("Choose new sound", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// This is the Choose File dialog (uses aFileDialog library)
// to get the file replacement
FileChooserDialog dialog1 = new FileChooserDialog(context);
dialog1.show();
dialog1.addListener(new OnFileSelectedListener() {
@Override
public void onFileSelected(Dialog source, File file) {
// TODO Auto-generated method stub
source.hide();
Log.e("App Debugging", file.getAbsolutePath());
String fileReplacement = file.getAbsolutePath();
}
@Override
public void onFileSelected(Dialog source, File folder,
String name) {
// TODO Auto-generated method stub
}
});
}
})
.setNegativeButton("Restore default", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog dialog = builder.show();
TextView messageText = TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
// Create the AlertDialog object and return it
return builder.create();
}
編集:これまでの私の調査結果は次のとおりです:重力builder.show();
を設定した後に別の呼び出しを追加すると動作するようになりますmessageText
が、最初のダイアログを閉じた直後に別のダイアログがポップアップします。