Is there any way to make my Dialog view full screen, i.e dialog occupy the entire screen (like an Activity). I tried using the LayoutParams and styles like
Following code works in my case :
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.mydialog2);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
Create your Custom Dialog as
Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
Give its constructor a non-dialog theme, such as android.R.style.Theme or android.R.style.Theme_Light.
Code by @Bob.
Dialog dialog = new Dialog(context, android.R.style.Theme_Light);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.MyCustomDialogLayout);
dialog.show();
For full screen dialog you should extend DialogFragment
it will provide Fragment
life cycle methods and this is the recommended way in Android developer documents you can use simple Dialog
or AlertDialog
also.
When you create dialog instance just use android.R.style.Theme_Black_NoTitleBar_Fullscreen
theme with context like this :
Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
or
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
This will show the dialog in full screen.
1.custom your dialog style
<style name = "MyDialog" >
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name = "android:windowContentOverlay" >@null</item >
<item name = "android:colorBackgroundCacheHint" >@null</item >
<item name = "android:backgroundDimEnabled">true</item>
<item name = "android:windowBackground" >@android:color/transparent</item >
</style >
2 :custom your dialog
WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
final Dialog dialog = new Dialog(this, R.style.MyDialog);
View view = LayoutInflater.from(this).inflate(R.layout.layout_dialog, null);
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialog.setContentView(view);
dialog.getWindow().setGravity(Gravity.BOTTOM);
dialog.getWindow().setWindowAnimations(R.style.mydialog_Style);
dialog.show();
Try this
dialog = new Dialog(context,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);