简体   繁体   English

始终保持对话/活动在顶部

[英]Keep dialog/activity always on the top

How to keep a dialog/activity on the top of other activities, no matter if user switch between activities,it should be alive all the time. 如何将对话/活动保持在其他活动的顶部,无论用户是否在活动之间切换,它都应该一直处于活动状态。

查看“显示”,“隐藏”按钮

You can use Relative layout as a parent, by using Relative Layout, you can overlap the other layout. 您可以使用相对布局作为父级,通过使用相对布局,您可以与其他布局重叠。 So, you have to use to two child layout of relative layout. 所以,你必须使用相对布局的两个子布局。 In the one child you will have popup, and in another layout you have to keep changing your layout.. 在一个孩子中,您将有弹出窗口,而在另一个布局中,您必须不断更改布局。

If you want this across multiple activities. 如果您希望跨多个活动。 You must create a separate layout and include that in all activities, and create an interface to handle the button events in the popup. 您必须创建一个单独的布局并将其包含在所有活动中,并创建一个界面来处理弹出窗口中的按钮事件。

or 要么

You can create a base activity, having above mentioned layout, and extends that activity in all other activities where you want this layout. 您可以创建具有上述布局的基本活动,并在您希望此布局的所有其他活动中扩展该活动。

Regards, Yuvi 此致,Yuvi

Personnaly, I will do something like that : Personnaly,我会做那样的事情:

1) Create a class which extends from DialogFragment : 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) Then in your activities : 2)然后在你的活动中:

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

3) And you put in a bundle the type of the dialog that the next activity can get it and show it again. 3)然后你输入一个对话框的类型,下一个活动可以获得它并再次显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM