Is there a solution to create an Alert Dialog with no borders around? If I create a layout and attach it to the Alert Dialog, I have my layout shown, but it's surrounded by the default dialog borders. Any way to cut them off? Thanks in advance.
Here is one way (if you don't like this particular example with the green border, scroll below to see a second one I found).
Here is another example (this one gives you an example without a border, and one with a border. The explanations are in Japanese, but the code is given for both.)
Hi if you use your own layout then set this in your styles.xml
<style name="Theme.Transparent_layout" parent="android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
and set this style in your manifest file
<activity android:name=".Main" android:theme="#style/Theme.Transparent_layout" />
Related
I use Acr.UserDialogs to create cross-platform dialogs from a Xamarin Shared/PCL project. Acr.UserDialogs contains a method to create a prompt which (in Android) is an AlertDialog whose View is set to an EditText. Unfortunately the View/EditText has no margin/padding which results in it reaching until the outer left and right limits of the dialog - which looks pretty ugly. Due to it being a library I have no ability to change how exactly the EditText or the AlertDialog are created (rather than editing the libraries code on GitHub myself but that's a way I try to avoid for now if possible). What the library supports is the possibility to pass an AndroidStyleId into the call that it uses instead of the default Android AlertDialog style (new AlertDialog.Builder(activity, passedAndroidStyleId)).
Now, my idea is to create a style that defines a custom margin/padding/inset to the View of the AlertDialog kind of as follows and pass it in.
<style name="CustomPromptDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="viewInset">10dp</item>
</style>
Problem is I can't find any resources listing which "properties" can be set in a style or how they are named, so my only idea was to ask here:
Is there any way to achieve what I'm trying to do? And if yes, how?
You can set the style like this to change the form of the Alertdialog. This the method for globel setting.
<style name="MainTheme" parent="MainTheme.Base">
<item name="android:datePickerDialogTheme">#style/Theme.picker</item>
<item name="alertDialogTheme">#style/Theme.alert</item>
</style>
<style name="Theme.alert" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<item name="colorAccent">#FFC107</item>
<!-- Used for the title and text -->
<item name="android:textColorPrimary">#FFC107</item>
<!-- Used for the background -->
<item name="android:background">#4CAF50</item>
<item name="viewInset">10dp</item>
I have the following in my styles.xml
<style name="dialog_style" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#ffaaaa00</item>
<item name="android:background">#ff444400</item>
<item name="android:textColorPrimary">#ffa25600</item>
</style>
(The horrible colours are for testing only!)
This gives the following
What I want is a dark/black background but when I do that, the text is unreadable.
Q: How do I change the text colour of "Cut", "Copy"...?
tia,
Kevin
I think it's a little bit better solution than user3247782's,
<style name="CustomAlertDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
...
<item name="android:popupBackground">#android:color/transparent</item>
</style>
You can change them by following style names:
<item name="colorAccent">#color/twoCuteSelectionHandlersColor</item>
<item name="android:textColorHighlight">#color/selectionColor</item>
Also you can set highlight color directly for pacific EditText using android:textColorHighlight attribute in xml layout or programmatically:
et.setHighlightColor(color);
For context menu you need create your own context menu. check this question for how disabling default context menu and implementing custom menu.
This isn't really an answer. The black-on-black edit menu is only generated from an EditText contained in an AlertDialog. The same code in a Fragment gives black-on-white.
So I "solved" my problem by converting the AlertDialog into a Fragment.
The original question, though, is still unanswered.
Alert Dialog and Popup Menu generaly take the color of #ColorAccent as the background. So try changing the colorAccent or just inflate a custom xml with the specifications you want.
Just change the parent of it from Theme.Material.Light to Theme.Material .
It will make the text white, there.
I fixed it by setting a background color with opacity in the style of the alertdialog
In styles.xml
<style name="AppCompatAlertDialogStyle">
...
<item name="android:background">#color/black_overlay</item>
...
</style>
In colors.xml
<color name="black_overlay">#66000000</color>
If you use MaterialAlertDialogBuilder then you can define background color through colorSurface attribute.
Then in styles you can just set background to transparent.
android:background="#android:color/transparent"
Dialog will use the one define in colorSurface and "copy/paste" will use default system colors (e.g. white).
I've been working on an app and I've reaching the point where it requires me to display a menu window in the middle of the screen.
I've been using an AlertDialog object filled with a custom View but now it was required of me to "surround" the window with a semi-transparent white glow as opposed to the default grayish one. I did a similar with the fade-in color of some navigation drawers I have on my app but in that case I had a specific method to quickly help me solve that problem. So far I haven't found anything that helps me solve this one.
I tried creating a default style with a new "windowBackground" value but I encountered 3 problems from the get-go:
I'm no longer able to shut the AlertDialog down by clicking outside the layout (I'm guessing because by changing the color that way everything is now the layout)
The menu window is now surrounded by a black outline that wasn't there before
By using the filtering search inside the layout, which manipulates the members of a list, the window collapses on itself
Is there any way to accomplish what I want more or less directly?
I'm not really sure about it, but you can use this in your styles.xml
<style name="MyDialogTheme" parent="android:Theme.AppCompat.Light.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#color/your_light_color</item>
<item name="android:backgroundDimEnabled">false</item>
And if you want to dismiss the dialog when clicking outside, use this:
dialog.setCanceledOnTouchOutside(true);
or
<item name="windowCloseOnTouchOutside">true</item>
in your styles.xml
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
Currently, I'm using this to show my application background as phone wallpaper.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER,
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
But for some reason when I start my application by pressing the icon. It just shows the activity screen with the icons on the home screen. I didn't use dialog but it looks like a dialog because layout is just set that way. So I just want to show the wallpaper whenever this activity is running. But it only shows the wallpaper only after the next event occurs such as switching to different activity. I already put that code on onCreate() and whenever I do setContentView()..... Is there way to do such thing or there is just no way?
For users of AppCompat, just use the following in your styles.xml, no need for code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowShowWallpaper">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
</style>
After long search and trial and error. I've found the solution to what I wanted. It was just creating separate themes.xml file and just tweak the Theme.Dialog which is already defined in default android themes.xml. All I did was change the Animation part. Originally in android themes.xml the line looks like this.
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
but since modifying in android themes.xml doesn't take the effect. I just created my own themes.xml as I said above and just set parent as android:Theme.Dialog. And added a line like this.
<item name="android:windowAnimationStyle">#android:style/Animation</item>
Thanks for the help and I hope this solution helps others.
Use following code -
rl = (RelativeLayout)findViewById(R.id.someid);
//relative layout is my root node in main.xml (yours may be linearlayout)
WallpaperManager wm = WallpaperManager.getInstance(this);
Drawable d = wm.peekDrawable();
rl.setBackgroundDrawable(d);// You can also use rl.setBackgroundDrawable(getWallpaper);