Android comes with the dialog style generally does not meet their own requirements, that requires dialog customization.
In fact, the activity can also exist in the form of dialog, we only need to set its theme property in the manifest file:
<activity
Android:name= ". Editactivity "
Android:theme= "@android: Style/theme.dialog"
>
</activity>
The general Activity form of the dialog, touch its outside will be dismiss, then, how can we prevent it from being dismiss away?
To achieve this, you actually need only one code:
Setfinishontouchoutside (False), which is a bit like Popupwindow's setoutsidetouchable (false);
To press the return key and not disappear, simply mask the return key or override the Backpress method
@Override
public boolean onKeyDown (int keycode, keyevent event) {
if (keycode = = Keyevent.keycode_back) {
return true;
}
Return Super.onkeydown (KeyCode, event);
}
@Override
public void onbackpressed () {
By default, the finish () method is called
Super.onbackpressed ();
}
This is how the activity was supposed to be implemented.
public void onbackpressed () {
if (!mfragments.popbackstackimmediate ()) {
Finish ();
}
}
This is not enough, the activity in the form of dialog display, the width will be relatively small, which requires us to give the width:
WindowManager manager = Getwindowmanager ();
Displaymetrics displaymetrics = new Displaymetrics ();
Display display = Manager.getdefaultdisplay ();
Display.getmetrics (Displaymetrics);
int width = displaymetrics.widthpixels;
int height = displaymetrics.heightpixels;
Windowmanager.layoutparams params = GetWindow (). GetAttributes ();
Params.width = (int) (width*0.8);
GetWindow (). SetAttributes (params);
So we set the width of the activity.
Customizing dialog-----Activity