Android中的全屏DialogFragment(通过ActionBar)

时间:2013-04-27 15:21:58

标签: android android-fragments fullscreen android-dialogfragment

我在全屏显示DialogFragment时遇到了一些问题。在我的应用程序中,我有一个片段,当你点击某个按钮时它会调用DialogFragment。但DialogFragment只填充片段区域(在操作栏下方)。我希望它能填满所有屏幕:http://img845.imageshack.us/img845/8682/myimage2.png

任何帮助?

     public class ItensActivity extends Fragment {
             ... 
            public void openDialogItens()
            {       
                dialog = new ItemDialog();      
                dialog.show(getFragmentManager(), "");
                getFragmentManager().executePendingTransactions();  

            }

            public static class ItemDialog extends DialogFragment
                {


                   @SuppressWarnings("deprecation")
                   @Override
                   public Dialog onCreateDialog(Bundle savedInstanceState) {
                      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());        
                      builder.setView(getContentView());
                      Dialog dialog = builder.create();
                      dialog.setCanceledOnTouchOutside(true);
                      WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                      lp.copyFrom(dialog.getWindow().getAttributes());
                      lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
                      lp.height = WindowManager.LayoutParams.FILL_PARENT;
                      dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                      dialog.getWindow().setAttributes(lp);   
                      return dialog;
                  }

            private View getContentView() {
                   LayoutInflater inflater = getActivity().getLayoutInflater();
                   View view = inflater.inflate(R.layout.popup_item, null);
                   return view;
            }
            }    

3 个答案:

答案 0 :(得分:3)

所以,经过大量的搜索,我没有找到使用API​​ 5覆盖动作栏的DialogFragment。但是我找到另一种方法来使Fragment在屏幕上调用一个新的活动,主题是一个对话框。这个解决方案对我有很大的帮助,所以,我在这里分享它: https://stackoverflow.com/a/12275009/2327056

  @StrikeForceZero使用google小组帖子的想法,我能够把它拉下来   造型活动。你想要修改高度和宽度   您选择的“动态”尺寸最好。然后设置什么   你想要的ActionBar按钮

<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
    <item name="android:windowIsFloating">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowSoftInputMode">stateAlwaysHidden</item>
    <item name="android:windowActionModeOverlay">true</item>
    <item name="android:windowIsTranslucent">true</item>
</style>
     

-

public static void showAsPopup(Activity activity) {
    //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
    activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
    activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
            WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    LayoutParams params = activity.getWindow().getAttributes(); 
    params.height = 850; //fixed height
    params.width = 850; //fixed width
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    activity.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 
    setContentView(R.layout.activity_main);
}

答案 1 :(得分:1)

我找到的最简单方法

Dialog dialog=new Dialog(this,android.R.style.Theme_Black_NoTitleBar_Fullscreen);
        dialog.setContentView(R.layout.frame_help);
        dialog.show();

答案 2 :(得分:0)

在调用#show时,您可以标记对话框fragmet以使用Dialog而不是嵌入的片段。

myDialogFragment.show(getFragmentManager(), "dialog")

这将创建一个对话框,该对话框将覆盖在操作栏和状态栏的顶部(如果您愿意,可以手动重新添加)。