Can't Get Transparent Dialogfragment
I have a dialog Fragment which look like that. AlertDialog ad = builder.create(); Drawable d = new ColorDrawable(Color.BLACK); d.setAlpha(130); ad.getWindow().setBackgroundDrawabl
Solution 1:
The issue is in default dialog theme. Based on this and this answers it's much easier to achieve your target.
The Activity should be like the following:
publicclassMyActivityextendsFragmentActivity {
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
}
@OverridepublicvoidonBackPressed() {
MyDialogFragment.newInstance("title title").show(getSupportFragmentManager(), "dialog");
}
}
And fragment:
publicclassMyDialogFragmentextendsandroid.support.v4.app.DialogFragment {
/**
* Create a new instance of MyDialogFragment, providing "title"
* as an argument.
*/static MyDialogFragment newInstance(String title) {
MyDialogFragmentfrag=newMyDialogFragment();
Bundleargs=newBundle();
args.putString("title", title);
frag.setArguments(args);
return frag;
}
@Overridepublic Dialog onCreateDialog(Bundle savedInstanceState) {
Dialogdialog=newDialog(getActivity(),android.R.style.Theme_Translucent_NoTitleBar);
finalViewview= getActivity().getLayoutInflater().inflate(R.layout.share_or_die, null);
finalDrawabled=newColorDrawable(Color.BLACK);
d.setAlpha(130);
dialog.getWindow().setBackgroundDrawable(d);
dialog.getWindow().setContentView(view);
final WindowManager.LayoutParamsparams= dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.CENTER;
dialog.setCanceledOnTouchOutside(true);
return dialog;
}
}
Also, be sure to do the following: before setContentView()
in the activity, getWindow().requestFeature(Window.FEATURE_NO_TITLE)
should be added in order to use *NoTitleBar
style.
The result is (I've used LinearLayout
with single TextView
inside):
Solution 2:
I hope it can help you
@OverridepublicvoidonStart() {
super.onStart();
Windowwindow = getDialog().getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.dimAmount = 0.0f;
window.setAttributes(windowParams);
}
Solution 3:
None of the above solutions worked for me. What i found to work was to make sure that I had imported android.support.v7.app.AlertDialog instead of the generic app.alertdialog.
Hope this helps others too.
Solution 4:
It works for me:
getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Post a Comment for "Can't Get Transparent Dialogfragment"