6

Im在全屏中显示DialogFragment中存在一些问题。在我的应用程序中,我有一个片段,当你点击某个按钮时,它会调用一个DialogFragment。但DialogFragment只是填充片段的区域(在操作栏下方)。我想它填写所有这样的屏幕:http://img845.imageshack.us/img845/8682/myimage2.pngAndroid中的全屏DialogFragment(通过ActionBar)

任何帮助吗?

 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; 
      } 
      }  
+0

我不确定我是否理解你想要的,但是如果你想要一个“全屏”片段,为什么要使用DialogFragment?改用普通的碎片。 – TomTasche 2013-04-27 16:24:31

+0

这是因为我想显示它像一个弹出/对话框,显示它的背后是什么,类似的:http://i.stack.imgur.com/uV5Jd.png。但DialogFragment没有覆盖操作栏 – 2013-04-27 16:34:42

+0

所以...你不想要一个* fullscreen *对话框,而是一个部分覆盖你的ActionBar的对话框,对吧? – TomTasche 2013-04-27 16:35:59

回答

3

于是,经过搜索了很多,我没有找到反正让DialogFragment使用API​​ 5.覆盖的动作条,但我觉得一个替代的方式来做到这一点使得片段调用屏幕上的新活动以对话为主题。该解决方案帮助了我很多,所以,我在这里分享它:使用这个想法从谷歌组后 https://stackoverflow.com/a/12275009/2327056

@StrikeForceZero我能够把它关闭 造型的活动。您希望将高度和宽度修改为您所选择的“动态”尺寸的 。然后设置任何 动作条按钮,你想

<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

把它放在'DialogFragment'中 'public void onCreate(Bundle savedInstanceState){ \t \t super.onCreate(savedInstanceState); \t \t this.setStyle(STYLE_NO_FRAME,android.R.style.Theme_Wallpaper); \t} \t' – CarlCarrots 2013-12-19 03:56:23

1

我发现

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

可以标志你对话fragmet,而不是使用对话框的最简单方法调用#show时嵌入的片段。

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

这将创建一个叠加在动作条和状态栏(可手动添加回去,如果你愿意的话)的顶部的对话框。