[英]Dim the background of an activity in android
我有一个问题,我在透明背景的另一个活动上展示了一个活动,但我想在昏暗的背景下显示相同的内容。 我怎样才能做到这一点?
这是完整的代码:
WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
layoutParams.dimAmount = 0.75f;
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setAttributes(layoutParams);
在扩充布局后立即放置此代码。
在drawable文件夹名称下创建一个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);
尝试这个:
WindowManager.LayoutParams wp = getWindow().getAttributes();
wp.dimAmount = 0.75f;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.