I have a custom AlertDialog
style that makes the AlertDialog
box transparent. It works fine except that when I inflate my desired transparent layo
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">
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);
}
}
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));
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.