2013-04-04 108 views
3

如何將對話/活動保持在其他活動的頂層,無論用戶在活動之間切換,它都應始終保持活躍狀態​​。始終將對話框/活動保持在最前面

Look at Show, Hide buttons

+0

在onResume()中顯示每個活動的onResume()中的對話消除它在onPause() – Raghunandan 2013-04-04 13:33:58

+0

@Raghunandan以及,我認爲這不是一個好方法 – azimov 2013-04-04 13:39:27

+0

你認爲這不是一個好方法? – Raghunandan 2013-04-04 13:40:21

回答

3

您可以使用相對佈局作爲家長,通過使用相對佈局,您可以重疊的其他佈局。所以,你必須使用相對佈局的兩個子佈局。在一個孩子,你將彈出,並在另一個佈局,你必須不斷改變你的佈局。

如果你想這跨多個活動。您必須創建單獨的佈局並將其包含在所有活動中,並創建一個界面來處理彈出窗口中的按鈕事件。

您可以創建一個基地活動,具有上述佈局,在你想要這個佈局中的所有其他活動擴展了活動。

問候, Yuvi

1

Personnaly,我會做這樣的事情:

1)創建從DialogFragment擴展類:

public class MyDialogFragment extends DialogFragment{ 
     public static final int DIALOG_TYPE1 = 1; 

     public static MyDialogFragment newInstance(int dialogType) { 
       MainDialogFragment frag = new MainDialogFragment(); 
       Bundle args = new Bundle(); 
       args.putInt("type", dialogType); 
       frag.setArguments(args); 
       return frag; 
      } 

     @Override 
     public Dialog onCreateDialog(Bundle savedInstanceState) { 
       super.onCreateDialog(savedInstanceState); 
       int type = getArguments().getInt("type"); 
       Dialog result = null; 
       switch (type) { 
       case DIALOG_TYPE1: 
           result = new AlertDialog.Builder(getActivity()) 
           .setTitle("TITLE") 
           .setMessage("MESSAGE") 
           .setPositiveButton(android.R.string.ok, null) 
           .create(); 
           break; 
         default: 
           break; 
       } 
       return result; 
     } 
} 

2)然後在你的活動:

DialogFragment dialog = MyDialogFragment.newInstance(MyDialogFragment.DIALOG_TYPE1); 
dialog.show(getFragmentManager(), "DIALOG"); 

3)你把一捆下一個活動可以獲取並再次顯示的對話框的類型。