Dialog弹出后让下面的VIEW也能点击,以及返回键事件

来源:互联网 发布:知乎jennywang人肉 编辑:程序博客网 时间:2024/05/17 07:04

1. Window window  = getWindow();

        WindowManager.LayoutParams attributesParams = window.getAttributes();

// WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 失去焦点,从而下一层VIEW获得焦点

        attributesParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;

        attributesParams.dimAmount = 0.4f;//设置遮罩透明度

        int width = (int) (window.getWindowManager().getDefaultDisplay().getWidth() *0.8f);设置Dailog 宽度

//        

        window.setLayout(width, LayoutParams.WRAP_CONTENT); 



2.重写Activity 的

dispatchKeyEvent便可以在Dialog弹出时按返回键,监听到事件,此条件配合WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE  使用。

0 0