我希望能够更改对话窗口,即:不同的颜色和线条以及将文本分开的东西。
我已经浏览了整个互联网,我无法找到任何可以帮助我的东西。
这是我正在调用的函数....
public void userNameRequired(View view)
{
AlertDialog.Builder builder = new AlerdDialog.Builder(this);
TextView newMessage = new TextView(this);
newMessage.setText(" User Name is Required to be between 7 and 20 caracters long.");
newMesage.setGravity(Gravity.CENTER_HORIZONTAL);
builder.setView(newMessage);
TextView title = new TextView(this);
title.setText("!! NOTICE !!");
title.setGravity(Gravity.CENTER);
title.setTextSize(28);
title.setTextColor(Color.RED);
builder.setCustomTitle(title);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
}
});
builder.show();
}
答案 0 :(得分:0)
如 pha 所述,您可以为警报对话框指定自定义主题:
答案 1 :(得分:0)
解决方案1:
colors.xml
<color name="background_dark">#3F51B5</color>
在对话框中调用show()
后,设置背景颜色如下:
builder.getWindow().setBackgroundDrawableResource(android.R.color.background_dark);
解决方案2:
定义自定义主题
//assuming you have `@color/White` and `@color/colorPrimaryDark` defined in `colors.xml`
<style name="AlertDialogCustom" parent="@android:style/Theme.Dialog">
<item name="android:textColor">@color/White</item>
<item name="android:textStyle">bold</item>
<item name="android:headerDividersEnabled">true</item>
<item name="android:typeface">normal</item>
<item name="android:background">@color/colorPrimaryDark</item>
</style>
设置样式
AlertDialog.Builder builder = new AlerdDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
所以,这就是你的代码应该是这样的:
public void userNameRequired(View view)
{
AlertDialog.Builder builder = new AlerdDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
TextView newMessage = new TextView(this);
newMessage.setText(" User Name is Required to be between 7 and 20 caracters long.");
newMesage.setGravity(Gravity.CENTER_HORIZONTAL);
builder.setView(newMessage);
TextView title = new TextView(this);
title.setText("!! NOTICE !!");
title.setGravity(Gravity.CENTER);
title.setTextSize(28);
title.setTextColor(Color.RED);
builder.setCustomTitle(title);
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id)
{
}
});
builder.show();
}
AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.MyDialogTheme)
...
.create();