user2176764
user2176764

Reputation: 87

How to overlay an image above all activities in android

I want to overlay an image above all activities after some operation to have a feel like phone is locked. How can I do this programmatically in android ?

Upvotes: 0

Views: 1071

Answers (2)

Emil Adz
Emil Adz

Reputation: 41099

You can set a FrameLayout at the end of you XML layout file with an ImageView and "match_parent" dimension for both length and height. Set it's visibility to "gone" in the XML layout file. and the problematically in your code change it's visibility to visible to show this full screen Image and hide all the other components that are laid below it.

For example in your XML file put this at the end of the XML:

<FrameLayout 
    android:id="@+id/lockScreenLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone" >
   <ImageView
       android:id="@+id/imageView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"          
       android:background="@drawable/your_iamge"
       android:contentDescription="@drawable/your_iamge" />
</FrameLayout>

So it would be the child of your root xml element.

and then in code, do this:

lockScreenLayout = (FrameLayout) findViewById(R.id.lockScreenLayout);
lockScreenLayout.setVisibility(View.VISIBLE);

Upvotes: 1

Christophe Longeanie
Christophe Longeanie

Reputation: 430

One simple solution consists in setting your image as the background of the root view of your activities.

Upvotes: 0

Related Questions