I have an Activity A, and there is a button B in the view. If somebody presses B then I want a pop-up which can take some part of screen making the A invisible in that area but rest of A is visible but not active. How can I achieve this?
8 Answers
If you want to do this using an Activity instead of a Dialog, you can do this by setting the activity's theme to android:theme="@android:style/Theme.Dialog"
in the manifest - this will make the activity appear like a dialog (floating on top of whatever was underneath it).

- 4,894
- 1
- 17
- 11
-
somehow it didn't work for me :(. I tried to set up the theme using setTheme(android.R.style.Theme_Dialog). – bhups Jul 28 '10 at 15:04
-
Have you tried setting the theme to the activity in the manifest instead? – oli Jul 28 '10 at 15:40
-
7Perfect!! How do I remove the title? – Skynet Jan 20 '15 at 08:08
-
1use this in the manifest also: `android:label="Custom title bar"` – TheLogicGuy Jun 21 '20 at 21:48
For AppCompat, add
android:theme="@style/Theme.AppCompat.Dialog.Alert"
to the activity in AndroidManifest

- 1,232
- 2
- 12
- 20
Just to add on oli's answer, make sure to use the Dialog from the theme you are using in your application.
In my case I did android:theme="@android:style/Theme.Holo.Light.Dialog"

- 165
- 1
- 15
For appcompat this can be used in the manifest
<activity android:theme="@style/Theme.Base.AppCompat.Dialog.FixedSize" >
</activity>

- 1,012
- 1
- 9
- 21
Setting theme to android:theme="@android:style/android:Theme.Holo.Panel"
worked for me.
Steps -
1. Set theme for the activity in manifest file to android:theme="@android:style/android:Theme.Holo.Panel"
(This has to be changed to whatever theme is being used). Ex:
<activity
android:name=".EditActivity"
android:theme="@android:style/android:Theme.Holo.Panel"
android:label="@string/title_activity_edit" >
</activity>
- In the activity resource xml set appropriate padding and width on the root layout. I have set it to
0
and added a child layout at the beginning with alpha to show some part of the previous activity.

- 514
- 3
- 16
if you are working with Material Design you should use @android:style/Theme.Material.Dialog.NoActionBar

- 606
- 1
- 7
- 18
You can do it programicly
Create Class MyDialog
import android.app.Activity;
import android.app.Dialog;
import android.view.Window;
import android.widget.TextView;
public class MyDialoge{
Activity activity;
TextView txt_Message;
Dialog dialog;
public ViewDialog(Activity activity) {
this.activity = activity;
}
public void showDialog(String message){
dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.custom_progress_dialog);
txt_Message = dialog.findViewById(R.id.txt_message);
txt_Message.setText(message);
//if you want to dimiss the dialog
//dialog.dimiss()
dialog.show();
}
public void dimiss(){
try {
dialog.dismiss();
} catch (Exception e) {
e.printStackTrace();
}
}
}
After that crate the layout -> call it my_dialog
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Hello PopUp Message"/>
</RelativeLayout>
In your Activity
MyDialog myDialog = new MyDialog(MainActivity.this);
myDialog.showDialog("Say Hello to Me");
To dimiss
myDialog.dimiss();

- 557
- 4
- 7