java 如何更改 AlertDialog 消息的颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44618542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the color of an AlertDialog message?
提问by 8bit an3
I have an AlertDialog
and it's message is displayed, but the color of the text is white. It blends in with the background. I've tried changing the theme but it doesn't work. How do I change the color of the message?
我有一个AlertDialog
并且显示了它的消息,但文本的颜色是白色的。它与背景融为一体。我试过改变主题,但它不起作用。如何更改消息的颜色?
The relevant code:
相关代码:
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(MainActivityGame.this);
builder.setTitle("Name");
builder.setMessage("Are you ");
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Submit default name, go home
boolean isInserted = myDb.insertData(defaultName, triesTaken, difficultyText);
if (isInserted) {
Toast.makeText(MainActivityGame.this, "Your name was submitted", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivityGame.this, "Error, your name wasn't submitted\n Have you entered a default name?\n Go to Settings/Default Name to set it up", Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(MainActivityGame.this, MainActivity.class);
startActivity(intent);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
userName.setVisibility(View.VISIBLE);
submitName.setVisibility(View.VISIBLE);
submitName.setEnabled(true);
dialogInterface.dismiss();
}
});
builder.create();
builder.show();
回答by Meikiem
you can give style to your alert dialog like this:
您可以像这样为警报对话框赋予样式:
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogStyle);
and the style is like always:
风格一如既往:
<style name="AlertDialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="android:colorAccent">#f3f3f3</item>
<item name="android:textColor">#f3f3f3</item>
<item name="android:textColorPrimary">#f3f3f3</item>
</style>
回答by creativecreatorormaybenot
You can either use thismethod, like @KarimElGhandour mentioned or just create your custom Layout
in the res\layout
folder and then apply it with alertDialog.setView(LayoutInflater.inflate(R.layout.yourlayout), yourRootView
.
您可以使用这种方法,就像提到的@KarimElGhandour 一样,或者只是Layout
在res\layout
文件夹中创建您的自定义,然后使用alertDialog.setView(LayoutInflater.inflate(R.layout.yourlayout), yourRootView
.