我有一个问题,我正在显示一个活动在另一个活动透明的背景,但我想显示相同的暗淡背景。我怎样才能做到这一点呢?
完整代码:
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.dimAmount = 0.75f;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setAttributes(layoutParams);
将此代码放在您填充布局之后。
创建一个可绘制文件夹名称为window_dim.xml的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);
试试这个:
WindowManager.LayoutParams wp = getWindow().getAttributes();
wp.dimAmount = 0.75f;