簡體   English   中英

昏暗的android中活動的背景

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM