Custom AlertDialog Borders
I am creating a custom dialog. Its example code is: final AlertDialog dialog; protected AlertDialog createDialog(int dialogId) { AlertDialog.Builder builder; builder = new
Solution 1:
I don't think you can remove the borders by using AlertDialog.Builder
.
What you can do is create a CustomDialog
class that extends Dialog
and in the constructor of your CustomDialog
you inflate your customdialog.xml
.
Also you will need to create a custom style
for your dialog, that hides the borders. Here is an example:
<style
name="CustomStyle"
parent="android:Theme.Dialog">
<item
name="android:windowBackground">@color/transparent</item>
<item
name="android:windowContentOverlay">@null</item>
</style>
Also define the transparent color:
<color
name="transparent">#00000000</color>
And you will create your dialog using :
CustomDialog dialog=new CustomDialog(this,R.style.CustomStyle);
Solution 2:
Create a custom theme:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@null</item>
</style>
</resources>
then use it:
builder = new AlertDialog.Builder(parent, R.style.CustomDialog);
Update
The constructor above is indeed API 11+. To work around this you need to extend AlertDialog (since its constructors are protected
) and and then use constructor with theme parameter. To insert your custom view follow the instructions here - the FrameLayout
trick described at the beginning.
Post a Comment for "Custom AlertDialog Borders"