Java AlertDialog更改字体外观(大小、颜色、对齐)
我正在尝试在游戏中更改AlertDialog的属性,目前我正在使用以下方式构建它: 私有静态最终整数对话框_INFO=1Java AlertDialog更改字体外观(大小、颜色、对齐),java,android,Java,Android,我正在尝试在游戏中更改AlertDialog的属性,目前我正在使用以下方式构建它: 私有静态最终整数对话框_INFO=1 private Dialog dialog; @Override protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder = new AlertDialog.Builder(this); switch (id) {
private Dialog dialog;
@Override
protected Dialog onCreateDialog(int id)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
switch (id)
{
case DIALOG_INFO:
builder.setTitle("Game Information - Diego 1.0.1");
builder.setIcon(R.drawable.icon);
builder.setMessage("Test there \n\n");
builder.setCancelable(true);
dialog = builder.create();
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON);
break;
}
return dialog;
}
如果玩家点击了某个按钮,我将以如下方式显示此对话框:
showDialog(DIALOG_INFO);
一切正常,但我决定通过以下方式更改此对话框中使用的字体外观:
showDialog(DIALOG_INFO);
TextView TextView=((TextView)
findviewbyd(android.R.id.message))textView.setTextColor(Color.LTGRAY)
textView.setTextSize(13)
textView.setGravity(Gravity.CENTER) 但只有当我把这个代码放在showDialog(DIALOG\u INFO)之后,代码才起作用;这意味着每次显示对话框时我都必须创建新对象(TextView TextView=…),我的问题是,我不能在创建对话框时只创建一次吗
提前感谢。您可以为AlertDialog设置自己的contentView:
.....
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rootView = (ViewGroup) inflater.inflate(R.layout.YOUR_DIALOG_LAYOUT, null);
builder.setView(rootView);
.....
并用xml标记对话框布局