Change the style of AlertDialog
Asked Answered
C

2

5

When I run this code the alert dialog is shown but there is one white border around the dialog and also the borders are little round. I do not want this white border and I want to have real corners with angle of 90. I hope you understand what I am trying to do.

        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        Button bbb=new Button(MvcnContactList.this);
        ad.setView(bbb);
        alertDialog = ad.create();
        alertDialog.show();

enter image description here

Is there any way to style the alert dialog but not the text color or text size or something similar... I want to style the borders of the alert dialog, so setting just a theme maybe it is solution to this problem. But I do not know what properties to override.

Thanks,

EDIT: For example this style override the textColor to 00FF00 , and that is cool, but which property should I override to make the corners not round and tho remove that white boreder

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AlertDialogCustom" parent="@android:style/AlertDialog">
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
        <item name="android:textSize">10sp</item>
    </style>
</resources>
Claudette answered 4/11, 2011 at 15:41 Comment(2)
Maybe this could help you : #2423062Revenue
it is good link but i doesn't override the properties for the border...Claudette
C
15

I found solution with the wrapper, where you can set a theme (style) to anything in the current context. I set R.style.MyTheme as style to my alert dialog and I customized that view to my own taste.

ContextThemeWrapper ctw = new ContextThemeWrapper( this, R.style.MyTheme );
        AlertDialog.Builder builder= new AlertDialog.Builder( ctw );
Claudette answered 7/11, 2011 at 13:27 Comment(2)
But what property did you override in the theme in order to remove the rounded corners and border? I'm having the same issue..Lagan
could you please explain/provide a code sample for how you have removed the white border?Countersink
N
1

You answered your question yourself but it did not work for me, so here's my answer hope to be helpful for everyone who need it:

<style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>

</style>

Put this style in res\values\styles.xml file and just set the theme of your activity to it in your Manifest. Like this:

android:theme="@style/PauseDialog" 
Novelize answered 22/9, 2013 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.