android dialog transparent - android

I want to get rid of the border in my dialog box and make it look absolutly transparent, as if the image is on the top of screen.
My dialog xml is -
<?xml version="1.0" encoding="utf-8"?>
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:visibility="invisible"/>

Try below code
Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

try this:
mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));

To give a translucent effect, say 50% opacity, use:
Drawable d = new ColorDrawable(Color.BLACK);
d.setAlpha(130);
mDialog.getWindow().setBackgroundDrawable(d);
'130' can be changed (0-255) to acheive desired opacity.

try this:-
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(R.layout.splash);
dialog.show();

For API 11+
Dialog mDialog = new Dialog(mContext, android.R.style.Theme_Holo_Light_Panel);

The simplest way of doing this is that in your DialogFragment's onCreate() method, call
setStyle(DialogFragment.STYLE_NO_FRAME, 0);
And if the view you returned in onCreateView does not have a background specified, the dialog's background will be just transparent.
Why? DialogFragment.STYLE_NO_FRAME means that OS will not do any drawing in the window of the dialog, and your view is 100% responsible for drawing everything about the dialog.

The accepted answer causes issue with devices that have a notch, as the statusbar completely disappears and shows an ugly white background.
Instead, the right way for this is to define your own style.
<style name="FullScreenDialogTheme" parent="Theme.MaterialComponents.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:statusBarColor">#color/colorPrimary</item>
</style>
Now, this will make the window not have borders and be transparent over the screen.

Related

DialogFragment gravity not showing dialog completely in corner

I want dialog to appear completely in corner. I am setting gravity this way:
Window win = dialog.getWindow();
WindowManager.LayoutParams wmlp = win.getAttributes();
wmlp.gravity = Gravity.TOP | Gravity.RIGHT;
wmlp.horizontalMargin = 0;
wmlp.verticalMargin = 0;
Margins don't affect anything here. Layout inspector also doesn't work on dialog so I can't really inspect what is setting margin/padding.
Can I show this dialog fragment completely in corner (without recreating custom overlay fragment over whole screen that acts as a dialog)?
That extra padding/margin may have something to do with the background drawable. Change the style of your dialog to set android:windowBackground and android:background to be transparent by doing something like this:
<style name="TransparentDialog" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
</style>
(I believe that android:windowBackground is important here, and you may not need to set android:background.)
Thanks goes to andrew who answered this question for helping to provide a solution.

Changing Background dim color for dialog appears in android

Hi I have to chage the dim color of dialog in my theme to white, so that by setting layoutParams.dimAmount = 0.5f; i can get blur white in dialog background.
I am using
<style name="MyDialog" parent="#android:style/Theme.Holo.Light.Dialog">
<item name="android:windowBackground">#color/dialog_dim_background</item>
</style>
and following below references
How do I create a transparent Activity on Android?
Custom screen dim with Dialog
It is a very old question, but i'd like to add n answer to it. I faced the same problem and googled a lot. Then came up with my own solution.
First of all, I removed the dim at all with this
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
And then I opened my layout(it was RelativeLayout) and put this view in it as the last element
<View
android:id="#+id/shade"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/primaryShadow"
android:visibility="invisible"/>
The background color is the color you want to use as your dim color. As you can see, it is invisible when created. So you'll need to find it in you Activity and set it's visibility before you launch the dialog to View.VISIBLE. When you cancel dialog, set it to View.INVISIBLE again. And that's it.
I know it's very old question but this will help out surely to someone who is using AppCompatActivity or ActionBarActivity. If you are setting a dialog to your activity or say DialogActivity then also the below will work!
dialog = new Dialog(ActivityName.this);
dialog .setCancelable(false);
dialog .setContentView(R.layout.dialog_layout);
Window window = dialog.getWindow();
if(window != null){
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setDimAmount(0.5f);
//If you are setting a dialog activity
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Double dialogWidth = displayMetrics.widthPixels * 0.50;
window.setLayout(dialogWidth.intValue(),
WindowManager.LayoutParams.WRAP_CONTENT); //Setting it cover half of the screen width
}
dialog.show();
Just before you dismiss the dialog,
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog.dismiss();
//If you are setting a dialog activity, create a style in styles.xml:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.Dialog">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
And in your Manifest, set the theme:
<activity android:name=".view.POSSelectCustomerDialogActivity"
android:theme="#style/MyTheme"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"/>
Ok here is how I do that "I don't know how will these behave with the blur flag though"
I create a custom layout for the dialog with a background color of my choosing .
set the dialog to fill screen
remove the dim behind flag
Code snippet
Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dailog_layout);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(0));
dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
dialog.getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Best of luck

Create a transparent dialog on top of activity

Background
I'm trying to put a layer on top of the current activity which would have explanation of what is going on on the current screen, similar to what occurs on contact+ app .
I know there are some solutions for this (like the showCase library and the superToolTips library ) , and I also know that I can create a view and set it on top by adding it to the window of the activity , but I need put a whole dialog layer on top.
Problem
No matter what I try, each solution doesn't work the way I need it to work.
in short , what I need is:
full screen dialog.
no change (not visual and not logical) to the action bar, notification bar, and content of the activity behind, meaning that everything behind the dialog stays the same it was shown a moment before the dialog was shown.
be transparent except for the views I use for the dialog, which should be shown normally.
what I've tried
Sadly, I've always got only a part of the things I needed.
here's my code:
styles.xml:
<style name="full_screen_dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>
MainActivity.java:
...
final Dialog dialog = new Dialog(this, R.style.full_screen_dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
dialog.getWindow().setFormat(PixelFormat.TRANSLUCENT);
dialog.show();
This code will put the layout on top of the activity, but sadly it doesn't have any transparency , even though I've set it . The layout I've used is very simple which is why I don't post it.
Question
what am I missing ? what should be done to fix the code?
how can I make the dialog both transparent, full screen AND that it won't change the action bar and notifications bar.
Working solution
EDIT: after finding a good solution, here's the working code:
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.floating_tutorial);
final Window window = dialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
Just change the background color of your Dialog:
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Edit:
This prevents the dim effect:
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Just add this, it really works!
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:windowBackground">#android:drawable/alert_dark_frame</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>

Dialog in full Screen

My question is i don't want to show transparent dialog in full screen
below is the code i used
dialog = new Dialog(this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.enterjoinseecode_dialog);
CustomDialog theme
<style name="CustomDialogTheme" parent="#android:style/Theme.Translucent.NoTitleBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowFullscreen">false</item>
</style>
Please some one helps me where i went wrong
Try this.Create your view for Dialog like below.
<RelativeLayout
android:layout_width="450dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical" >
// Here you can add your component.
</RelativeLayout>
And set your dialog this view.
dialog = new Dialog(this, R.style.CustomDialogTheme);
dialog.setContentView(R.layout.enterjoinseecode_dialog);
That's it.Hope this will help you.
Create a activity with transparent background and for that particular activity define theme like this
<activity android:theme="#android:style/Theme.Dialog" />
And also if you want that activity to be exactly like dialog, then you can also use this
android:excludeFromRecents="true"
to remove it from the recent apps list.
some how with the following steps got the dialog with transparent effect with out full screen
No need of defining style "CustomDialogTheme" need to pass the theme argument for constructor as android.R.style.Theme_Translucent_NoTitleBar
and with in inflated xml just used background as android:background="#29000000" to make it transparent effect and layout_gravity property to position the dialog
if i use the above style CustomDialogTheme somehow its showing as a window instead of dialog because of that i applied direct theme to show that as dialog (not full screen)and to make it transparent effect with in xml i set the property background

change progressdialog background

In my android application I am using progress dialog in my splashscreen.
I would like to see only the progressbar with loading message without the background.
Is there any way that I can change the background to transparent in Android?
Please share your valuable suggestions.
ProgressBar should be placed on the Layout and then you have to set or change the progressbar in your activity.
Beware of setting the background before setting max, min, progress and text or it will not render correctly.
you can get it by defining the progressbar and the text in your xml file and you control it in your activity.
As MGS says, you can put the <Progressbar> in your layout xml file itself. Moreover you want to customize your ProgressDialog then you have to study the CustomDialog Tutorial in the Documentation. It explains everything about Dialog completely.
You can do this with the help of custom dialog instead of using progress dialog.
Custom dialog will be a better approach to do this .
Follow the link.
You can also use
android:background="#android:color/transparent"
in the background property of the parent layout in order to make it transparent.
Hope this will solve your problem
make layout .xml file which you want to display in Dialog then Create Object of Dialog
Dialog dialog = new Dialog(main.this);
dialog.setContentView(R.layout."your_layout");
dialog.setTitle("This is my custom dialog box");
dialog.setCancelable(true);
Create a dialog set set the dialog style to following:
<style name="CustomDialogTheme" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowNoTitle">true</item>
</style>
For ex:
Dialog dialog = new Dialog(main.this,R.style.CustomDialogTheme);
dialog.setContentView(<layout>);
Just put your progress bar in layout.

Categories

Resources