Transparent AlertDialog has black background
The problem is that AlertDialog builder
is actually not good for designing transparent dialog and will and always have this black background which is actually a Theme for it, instead use the Dialog
to create a transparent theme instead.
sample:
Dialog alertDialog = new Dialog(this);
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.tabs);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.show();
Using Dialog
does not require any theme manipulation for transparent background so it is basically easy.
In your R.layout.tabs
,
Replace
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/tabLayout"
android:background="#000000ff">
with
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/tabLayout"
android:background="@android:color/transparent">
Have you tried using something like this:
<style name="CustomDialog" parent="@android:style/Theme.Translucent">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
...
</style>
EDIT
Try this in java code
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
Those who are having still problem creating custom transparent dialog or alert dialog, can use this combination. I also wanted to show custom background this is what worked for me.
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
example:-
/**
* alert dialog
*/
public class ToolTipView extends AlertDialog {
public ToolTipView(@NonNull Context context) {
super(context);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_tool_tip_view);
}
}