Android 从“新建”按钮打开应用程序设置
我已经从我的应用程序顶部删除了默认的操作栏,并将其替换为我自己的自定义顶部菜单。这解决了许多问题,因为我正试图用我的应用程序实现这些目标 现在唯一的问题是我无法访问操作栏上的默认设置按钮。我本来打算创建自己的设置弹出窗口,但如果没有新的活动作为弹出对话框启动,我不确定如何创建。这与默认设置菜单弹出窗口不同Android 从“新建”按钮打开应用程序设置,android,Android,我已经从我的应用程序顶部删除了默认的操作栏,并将其替换为我自己的自定义顶部菜单。这解决了许多问题,因为我正试图用我的应用程序实现这些目标 现在唯一的问题是我无法访问操作栏上的默认设置按钮。我本来打算创建自己的设置弹出窗口,但如果没有新的活动作为弹出对话框启动,我不确定如何创建。这与默认设置菜单弹出窗口不同 有没有一种方法可以通过顶部的自定义操作栏复制此代码?在on button listener中使用此代码 startActivityForResult(new Intent(android.pr
有没有一种方法可以通过顶部的自定义操作栏复制此代码?在on button listener中使用此代码
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(), "");
检查