Show Dialog nearly full screen in my case (With Ac

2019-04-08 08:53发布

问题:

I am working with Android Support package.

I have created a dialog:

Dialog dialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);

Since I would like the dialog show in a full screen, so I applied the theme Theme_Translucent_NoTitleBar_Fullscreen to it & it works.

I have following two questions:

  1. I would like my dialog to show like full screen still but leave the top ActionBar not be covered by it, what Theme should I use then?

  2. How to have an gray color overlay to also show the view covered by the dialog (assume my 1st qustion has resolved)?

回答1:

  1. The only working solution I found is to implement pseudo-dialog based on fragment.
  2. This approach might cause some difficulties to do shadow. At least, I didn't do that.

Code sample how to do (1):

public class MyDialog extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // ... your code
}

public void show(FragmentManager fragmentManager) {
    FragmentTransaction ft = fragmentManager.beginTransaction();
    String tag = MyDialog.class.getName();
    ft.add(android.R.id.content, this, tag);
    ft.commit();
}

private void dismiss() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.remove(this);
    ft.commit();
}
}