我要存档的内容:我想要一个包含自定义视图的对话框,但我想要标准图标、标题、AlertDialog
.
我正在做的是这个自定义对话框类:
public class CustomDialog extends AlertDialog.Builder {
private Activity activity;
private View root;
public CustomDialog(Activity context) {
super(context);
this.activity = context;
}
public void setView(int layoutResID) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
root = inflater.inflate(layoutResID, (ViewGroup) activity.findViewById(R.id.dialog_root), false);
ScrollView scroller = new ScrollView(activity);
scroller.addView(root);
setView(scroller);
}
public void setCustomView(View v) {
ScrollView scroller = new ScrollView(activity);
scroller.addView(v);
setView(scroller);
}
public View getRoot() {
return root;
}
@Override
public AlertDialog create() {
AlertDialog dialog = super.create();
dialog.getWindow().getAttributes().width = LayoutParams.MATCH_PARENT;
return dialog;
}
}
这工作得很好,预计TextView
颜色在预 Honeycomb 和 Honeycomb 设备上不正确。我正在使用该Holo.Light
主题,因此标准文本颜色为黑色,但蜂窝设备之前的对话框的背景颜色也是如此。在 Honeycomb 设备上,对话框背景是白色的。所以我所做的是,我dialogTextColor=white
在文件夹和文件夹styles.xml
中添加了一个。然后我必须将样式属性添加到每个values
dialogTextColor=black
values-v11
TextView
我在自定义对话框中使用。这在 ICS 之前一直有效,并且很清楚为什么 -> v11。我可以更改它,但我想要一个自定义对话框,它可以做所有正确的事情:基于应用程序主题的 pre-Honeycomb、Honeycomb、ICS(以及将来会出现的任何内容)上的文本颜色、对话框的宽度、标准按钮、标题、图标AlertDialog
。