Show Dialog nearly full screen in my case (With ActionBar & overlay)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-21 12:38:39

问题


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();
}
}


来源:https://stackoverflow.com/questions/11396277/show-dialog-nearly-full-screen-in-my-case-with-actionbar-overlay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!