2011-11-29 80 views
2

我有一個問題,我顯示了一個活動與透明背景的另一個活動,但我想顯示相同的昏暗的背景。我怎樣才能做到這一點?昏暗的Android的活動的背景

+2

可能有幫助:http://stackoverflow.com/q/7132265/1007273 – hovanessyan

+0

嘿hovanessyan,我也這樣做通過它我得到了透明背景,我希望這個透明背景變暗。 –

+0

您可以通過API Demos.Its不準確地得到您想要的內容,但是,名稱爲「半透明模糊」的那個可能會對您有所幫助。 – Hiral

回答

2

試試這個:

WindowManager.LayoutParams wp = getWindow().getAttributes(); 
wp.dimAmount = 0.75f; 
13

下面是完整的代碼:

WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); 
    layoutParams.dimAmount = 0.75f; 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
    getWindow().setAttributes(layoutParams); 

將這個代碼,你吹的佈局之後。

3

下創建文件夾繪製名稱的XML作爲window_dim.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle" > 
<solid android:color="#000000" /> 
</shape> 

坐落在XML主要佈局屬性爲波紋管 -

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/mainLayout" 
... 

android:foreground="@drawable/window_dim" 
android:orientation="vertical" 
... > 

在活動設置主要佈局爲波紋管 -

mainLayout.getForeground().setAlpha(180); 
+0

簡單的解決方案,但在API 23之前不工作。任何方式之前,API 23? – ysfcyln