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

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  使用。

你可能感兴趣的:(Windows)