Android實現(xiàn)蒙板效果
本文實例為大家分享了Android實現(xiàn)蒙板效果的相關(guān)代碼,供大家參考,具體內(nèi)容如下
1、不保留標(biāo)題欄蒙板的實現(xiàn)
效果:

原理:
1、彈窗時,設(shè)置背景窗體的透明度
2、取消彈窗時,恢復(fù)背景窗體的透明度
關(guān)鍵代碼:
private void popupWindows(List<String> list){
//產(chǎn)生背景變暗效果
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、保留標(biāo)題欄蒙板的實現(xiàn)
效果:

原理:
1、根據(jù)需求,設(shè)置蒙板布局大小。
2、彈窗時,顯示蒙板布局
2、取消彈窗時,隱藏蒙板布局
關(guān)鍵代碼:
1、蒙板布局實現(xiàn):
<!-- 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); //隱藏蒙板
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。
相關(guān)文章
Android 實現(xiàn)長按彈出PopupMenu 菜單欄
這篇文章主要介紹了Android 實現(xiàn)長按彈出PopupMenu 菜單欄,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
Android判斷touch事件點是否在view范圍內(nèi)的方法
這篇文章主要介紹了Android判斷touch事件點是否在view范圍內(nèi)的方法,涉及Android事件響應(yīng)與view屬性操作的相關(guān)技巧,需要的朋友可以參考下2016-03-03
在Android中實現(xiàn)浮窗并添加吸邊效果的代碼示例
在 Android 中實現(xiàn)浮窗(懸浮窗)并添加吸邊效果,可以使用 WindowManager 來管理浮窗視圖,并通過觸摸事件來實現(xiàn)吸邊效果,以下是一個示例,展示如何創(chuàng)建一個浮窗并實現(xiàn)吸邊效果,需要的朋友可以參考下2025-02-02
flutter InheritedWidget使用方法總結(jié)
這篇文章主要為大家介紹了flutter InheritedWidget使用方法總結(jié)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11

