如何定制一个对话框的标题布局
-
20-09-2019 - |
题
在机器人,是有可能以自定义标题布局(图标+文本)的对话的布局?或者,我可以只设置标题文字的自定义字符串值?
感谢您。
解决方案
这是可能的,如果你设置的对话框和头都自定义布局更改对话框的标题。我只使用过这种方法来完全移除报头,但这应该为自定义首部工作:
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);
这是所有稍微更复杂(因为你必须设置对话框的布局,以及),但它比继承对话更容易。
其他提示
原来的对话框类似乎缺乏以设置图标的功能,但你可以轻松地扩展AlertDialog和设置自定义视图,你只需要像这样(你会用你的对话实例相同)
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);
}
}
不隶属于 StackOverflow