Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a transparent activity so that background activity is able to take events

Tags:

android

Is it possible in android that one transparent activity is on the top and a background activity is able to handle the events?

If yes then please refer the below image enter image description here

As in image i have one activity in background with button click and another activity with drawer. And i want that button in the background activity can able to handle events.

like image 294
Deepak Goel Avatar asked Jan 02 '12 09:01

Deepak Goel


People also ask

How to set transparent theme in android?

3 by just adding android:theme="@android:style/Theme. Translucent" in the activity tag in the manifest. This works fine for 2.2 also.

What is transparent activity?

In Android, we can create a transparent activity that will not be visible but your application will be running. The best part of this transparent activity is that you can create a transparent activity by just changing the resource file and we need not write the java or kotlin code for the same.


2 Answers

I was able to make this work with the following code in my transparent foreground activity

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Pass touch events to the background activity
        getWindow().addFlags(
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
...
        setContentView(R.layout.main);
}
like image 172
marmor Avatar answered Oct 17 '22 04:10

marmor


I have never tried, but creating a SlidingDrawer with a Fragment inside should work.

Using the Compatibility library will work till android 1.6!

 <SlidingDrawer
     android:id="@+id/drawer"
     android:layout_width="match_parent"
     android:layout_height="match_parent"

     android:handle="@+id/handle"
     android:content="@+id/content">

<fragment android:name="your.package.name.yourFragment"
        android:id="@+id/fragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

 </SlidingDrawer>

On your button, you will add:

public void animateOpen ()

Since: API Level 3 Opens the drawer with an animation.

like image 35
Waza_Be Avatar answered Oct 17 '22 05:10

Waza_Be