2013-12-24 38 views
3

我已從應用程序頂部刪除了默認操作欄,並將其替換爲我自己的自定義頂層菜單。這解決了我試圖用我的應用程序實現的許多問題。從新按鈕打開應用程序設置

現在唯一的問題是我無法訪問操作欄上的默認設置按鈕。我打算創建自己的設置,但是我不確定如果沒有新的活動作爲彈出式對話框啓動。這與默認設置菜單彈出不一樣。

有沒有一種方法可以將我的自定義操作欄複製到頂部?

+0

檢查[此](http://stackoverflow.com/a/17872878/1777090) –

回答

0

使用此代碼在按鈕偵聽

startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0); 
0

你可以使用一個DialogFragment使用自定義對話框,模擬設置彈出。

public class CustomDialogFragment extends DialogFragment { 

    @Override 
    public Dialog onCreateDialog(Bundle savedInstanceState) { 
     CustomDialog dialog = CustomDialog(getActivity()); 

     // Position the dialog window below your action bar 
     Window window = dialog.getWindow(); 
     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); 
     lp.gravity = Gravity.TOP | Gravity.RIGHT; 
     lp.y = 100; // action bar height 
     window.setAttributes(lp); 

     return dialog; 
    } 

    private class CustomDialog extends Dialog { 

     public CustomDialog(Context context) { 
      super(context); 

      // do not show the title of the dialog box and dismiss 
      // it if touched outside, as the normal settings pop up 
      requestWindowFeature(Window.FEATURE_NO_TITLE); 
      setCanceledOnTouchOutside(true); 

      // your custom layout 
      setContentView(R.layout.custom_layout); 
     } 

    } 
} 

然後用顯示它:

CustomDialogFragment popup = new CustomDialogFragment(); 
popup.show(getFragmentManager(), ""); 
相關問題