3
我已从应用程序顶部删除了默认操作栏,并将其替换为我自己的自定义顶层菜单。这解决了我试图用我的应用程序实现的许多问题。从新按钮打开应用程序设置
现在唯一的问题是我无法访问操作栏上的默认设置按钮。我打算创建自己的设置,但是我不确定如果没有新的活动作为弹出式对话框启动。这与默认设置菜单弹出不一样。
有没有一种方法可以将我的自定义操作栏复制到顶部?
我已从应用程序顶部删除了默认操作栏,并将其替换为我自己的自定义顶层菜单。这解决了我试图用我的应用程序实现的许多问题。从新按钮打开应用程序设置
现在唯一的问题是我无法访问操作栏上的默认设置按钮。我打算创建自己的设置,但是我不确定如果没有新的活动作为弹出式对话框启动。这与默认设置菜单弹出不一样。
有没有一种方法可以将我的自定义操作栏复制到顶部?
使用此代码在按钮侦听
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 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(), "");
检查[此](http://stackoverflow.com/a/17872878/1777090) –