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") 

這將創建一個疊加在動作條和狀態欄(可手動添加回去,如果你願意的話)的頂部的對話框。