警报对话框背景主题/颜色 [英] Alert Dialog background theme/Color
问题描述
我想设置AlertDialogue
主题或更改背景颜色.
I want to set AlertDialogue
theme or change background color.
尽管我知道它有一个默认主题,但是在不同版本中,我得到了不同的主题,因此我想针对所有版本进行修复.
Though I know it has a default theme but in different version I am getting different theme so I want to fix it for all version.
或者只是将背景颜色更改为白色
Or simply change background color as white
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
final SimpleAdapter adapter = new SimpleAdapter(getContext(), imagesWithNames, R.layout.lib_dialog_image,
new String[]{"name", "imageID","Spacing"}, new int[]{R.id.text1, R.id.image1,R.id.spacing});
return new AlertDialog.Builder(getContext()).setAdapter(adapter,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
((PlaceCallActivity) getContext()).OnSelected(WithNamesFragment.this.getClass(), (int) ((HashMap<String, Object>) adapter.getItem(i)).get("imageID"));
}
}).setCancelable(true).setTitle("PICK YOUR AVATAR").setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create();
}
请勿发布您的代码,请在此处告诉我应该在哪里进行更改.
Don't post your code please tell where I should make a change here.
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.AlertDialogCustom));
注意:上面的代码行可以做到,但是我想知道应该在哪里给AlertDialogue
Note : The Above line would do it but I want to know where I should give style for my AlertDialogue
推荐答案
在styles.xml
文件中创建样式,如下所示.
Create your style in your styles.xml
file as follows.
<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>
然后按如下所示使用Builder创建Alert Dialog
Then Create Alert Dialog
using Builder as follows
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this/getActvity(), R.style.AlertDialogCustom));
此处将当前类的Context和样式传递给ContextThemeWrapper
类构造函数.
Here passing the current class Context and style to the ContextThemeWrapper
class constructor.
这篇关于警报对话框背景主题/颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!