简体   繁体   English

昏暗的android中活动的背景

[英]Dim the background of an activity in android

I have a problem that I am showing an activity over another activity with transparent background but I want to show the same with dim background. 我有一个问题,我在透明背景的另一个活动上展示了一个活动,但我想在昏暗的背景下显示相同的内容。 How can I achieve this? 我怎样才能做到这一点?

Here is the complete code: 这是完整的代码:

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

Put this code right after you inflate the layout. 在扩充布局后立即放置此代码。

Create a xml under drawable folder names as window_dim.xml 在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>

Set main layout attribute in xml as bellow - 在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"
... >

In activity set main layout as bellow - 在活动中设置主要布局如下 -

mainLayout.getForeground().setAlpha(180);

Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM