I have a custom AlertDialog and I want to make it's background completely transparent. Normally to make an activity completely transparent, I do the following
set background to #00000000
in the xml layout
in the manifest set android:theme="@android:style/Theme.Holo.Dialog"
for the activity.
In onCreate add getWindow().setBackgroundDrawable(new ColorDrawable(0))
.
But now that I am dealing with a Dialog, how do I accomplish transparency?
Here is the dialog code:
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.activity_mine1,
(ViewGroup) findViewById(R.layout.mine1));
mine1 = new AlertDialog.Builder(this);
mine1.setView(dialoglayout);
mine1.show();
And my xml is just a relativeLayout with other child views:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000" >
...
</RelativeLayout>
Note: I have already looked at some similar posts here, but they don't seem to work.
My real reason is that the background that I really want to use, is not rectangular. I get it to work in an activity. But I want to use a dialog instead.
EDIT:
Further playing around, I have this style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomDialog" parent="android:Theme.Holo.Dialog">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources>
Which I add as
new AlertDialog.Builder(this, R.style.CustomDialog)
setVerticalScrollBarEnabled(true); wv. setBackgroundColor(Color. TRANSPARENT); wv. setPadding(5, 25, 5, 0); ImageView imgcartl=(ImageView)layout.
<style name="CustomAlertDialog" parent="android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">true</item>
<item name="android:width">300dip</item>
<item name="android:textColor">#FFFFFF</item>
</style>
Dialog connectionDialog = new Dialog(this, R.style.CustomAlertDialog);
connectionDialog.setContentView(set your view here);
connectionDialog.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With