本文介紹了使用 Dialog 自定義屏幕變暗的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 Android 中,當您彈出一個對話框時,它后面的屏幕會變暗.有什么辦法可以控制它的外觀嗎?例如使其變暗或使用某種模式?
In Android when you pop up a dialog the screen behind it dims. Is there any way to control what that looks like? For example making it dim more or less or using some kind of a pattern?
推薦答案
是的.你可以控制它.
創建對話框后:
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.dimAmount = 0.0f; // Dim level. 0.0 - no dim, 1.0 - completely opaque
dialog.getWindow().setAttributes(lp);
更新:您甚至可以在對話框后面添加模糊:
Upd: you can even add blur behind the dialog:
dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
Upd2:不推薦使用模糊從 API14 開始:
此常量在 API 級別 14 中已棄用.
不再支持模糊.
This constant was deprecated in API level 14.
Blurring is no longer supported.
這篇關于使用 Dialog 自定義屏幕變暗的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!