如何将dialog_more_information集中在以下代码中?是否有必要使用自定义视图?
提前致谢!
这就是我所说的>
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.more_information:
MoreInformationDialogFragment mDialog = new MoreInformationDialogFragment();
mDialog.show(getFragmentManager(), null);
return true;
default:
return false;
}
}
这是MoreInformationDialogFragment类>
public class MoreInformationDialogFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_more_information)
.setPositiveButton(R.string.dialog_visit_moma, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Uri uri = Uri.parse("http://www.somesite.org");
Intent SomeSite = new Intent(Intent.ACTION_VIEW, uri);
startActivity(SomeSite);
}
})
.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Cancel
setResult(RESULT_CANCELED); // is this really needed?
}
});
return builder.create();
}
}
答案 0 :(得分:0)
以下是如何做到的:
Dialog dialog = builder.create();
TextView messageText = (TextView)dialog.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
return dialog;