Android user dialog

I need to show a user dialog in an android app. The standard design of AlertDialog not acceptable. Android docs say:

Tip. If you need a special dialog, you can instead display Activity as a dialog instead of using the Dialog APIs. Just create and set its Theme.Holo.Dialog theme in the manifest:

What is it. Now the activity is displayed in the dialog box instead of full-screen mode.

It sounds promising. I did it, but transparency doesn't work! The background is always gray:

enter image description here

Here is the description in the manifest:

 <activity android:name=".MyDialogActivity" android:screenOrientation="portrait" android:theme="@android:style/Theme.Holo.Dialog.NoActionBar" > </activity> 

Here is the root of my activity:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:background="#00000000" android:layout_width="400dp" android:layout_height="wrap_content" > // Content ... // </RelativeLayout> 

I also tried android:background="@null" - the effect was the same. If I use android:background="#ff0000" , then it will be red (as it should be). But how to make it transparent?

Update

I finished with

 <style name="MyThemeDialogCustom" parent="android:Theme.Holo.Dialog.NoActionBar" > <item name="android:windowBackground">@color/transparent</item> <item name="android:colorBackgroundCacheHint">@null</item> </style> 
+7
source share
5 answers

create a theme as follows

 <style name="ThemeDialogCustom"> <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:windowBackground">@color/transparent</item> <item name="android:colorBackgroundCacheHint">@null</item> </style> 
+7
source

Try ...

You can avoid a gray background like this. Here I got a transparent background.

  ........ Dialog dialog = new Dialog(MainActivity.this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Window window = dialog.getWindow(); window.setBackgroundDrawableResource(android.R.color.transparent); dialog.setContentView(R.layout.popup_layout); Button dialogBtn= (Button) dialog.findViewById(R.id.btn); dialogBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //task } }); dialog.show(); ....... 
+4
source
 dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
+2
source
 dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); 
0
source

I used this as a style:

 <style name="DialogTransparent" parent="Theme.AppCompat.Dialog"> <item name="android:windowFrame">@null</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowIsFloating">true</item> <item name="android:windowContentOverlay">@null</item> <item name="android:windowTitleStyle">@null</item> <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> <item name="android:background">@android:color/transparent</item> </style> <!-- <item name="android:backgroundDimEnabled">false</item> --> 

it also has a transparent background, setting the brackgroundDimEnabled parameter to false so as not to display a gray background that displays with a dialog behind it.

0
source

All Articles