【问题标题】:How to change/update the custom layout of a Dialog on orientation change in android如何在android中的方向更改时更改/更新对话框的自定义布局
【发布时间】:2018-02-15 11:59:01
【问题描述】:

我试图在活动的 onConfigurationChange 中更改对话框的布局。 我在常规布局文件夹中创建了 2 个布局,另一个在 layouts-land 中创建,如果设备的方向是横向或纵向,我可以获取布局,然后单击以显示对话框。但是,如果我在对话框显示自定义布局时尝试更改方向,使用中的自定义布局不会更新。

请帮我解决这个问题。我不想使用 DialogFragment 来执行此操作,有没有更简单的方法可以通过使用常规 AlertDialog 来修复它。

谢谢。

【问题讨论】:

    标签: android android-layout android-xml android-alertdialog android-dialog


    【解决方案1】:

    您应该创建两种不同的布局,一种用于纵向,另一种用于横向。然后要求改变方向的布局。 搜索具有自己布局的警报对话框。

    LayoutInflater inflater = getLayoutInflater();
    View alertLayout = inflater.inflate(R.layout.layout_custom_dialog,null);
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Info");
    alert.setView(alertLayout);
    AlertDialog dialog = alert.create();
    dialog.show();
    

    【讨论】:

    • 嗨,Anuj,这正是我在做的事情。但布局不会随着方向变化而更新。它可以在纵向或横向模式下工作,但事务不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-26
    • 1970-01-01
    相关资源
    最近更新 更多