本文實例為大家分享了Android實現蒙板效果的相關代碼,供大家參考,具體內容如下
1、不保留標題欄蒙板的實現
效果:

原理:
1、彈窗時,設置背景窗體的透明度
2、取消彈窗時,恢復背景窗體的透明度
關鍵代碼:
private void popupWindows(List<String> list){  //產生背景變暗效果  WindowManager.LayoutParams lp=getWindow().getAttributes();  lp.alpha = 0.4f;  getWindow().setAttributes(lp);    ......省略號......  mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {      @Override      public void onDismiss() {        WindowManager.LayoutParams lp = getWindow().getAttributes();        lp.alpha = 1f;        getWindow().setAttributes(lp);      }    });   ......省略號......}2、保留標題欄蒙板的實現
效果:

原理:
1、根據需求,設置蒙板布局大小。
2、彈窗時,顯示蒙板布局
2、取消彈窗時,隱藏蒙板布局
關鍵代碼:
1、蒙板布局實現:
<!-- popup蒙板 --><LinearLayout android:id="@+id/ll_popup_hide" android:layout_width="match_parent" android:background="@color/hide_bg" android:orientation="vertical" android:layout_height="match_parent"></LinearLayout><color name="hide_bg">#88323232</color>
2、代碼處理
ll_popup_hide.setVisibility(View.VISIBLE); //顯示蒙板ll_popup_hide.setVisibility(View.INVISIBLE); //隱藏蒙板
以上就是本文的全部內容,希望對大家的學習有所幫助。
 
  | 
新聞熱點
疑難解答