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?
Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app is running in the background. These restrictions help minimize interruptions for the user and keep the user more in control of what's shown on their screen.
Using the Interface - onSlide which as a parameter slideOffSet of type float , can be used to dim the background.
It seems like you want to run an activity in background when it quits. However, activity can't be run unless it's on foreground. In order to achieve what you want, in onPause(), you should start a service to continue the work in activity. onPause() will be called when you click the back button.
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
<?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 -
<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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With