在Android中,是否可以自定义对话框的标题布局(图标+文本)布局?或者我只能设置标题文本的自定义字符串值吗?
谢谢。
谢谢。
如果您为对话框和标题栏设置自定义布局,则可以更改对话框的标题。我仅使用此方法完全删除标题栏,但这应该适用于自定义标题栏:
dialog = new Dialog(context);
Window window = dialog.getWindow();
window.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.my_dialog_layout);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);
这有点复杂(因为你还需要设置对话框的布局),但比子类化对话框要容易。
原始的Dialog类似乎缺少设置图标的功能,但是您可以轻松地扩展AlertDialog并设置自定义视图(与Dialog实例使用的相同),您只需要像这样:
class MyDialog extends AlertDialog {
public MyDialog(Context ctx) {
super(ctx);
LayoutInflater factory = LayoutInflater.from(context);
View view = factory.inflate(R.layout.dialog_layout, null);
setView(view);
setTitle("MyTitle");
setIcon(R.drawable.myicon);
}
}