当前位置 : 主页 > 手机开发 > android >

Android弹出对话框

来源:互联网 收集:自由互联 发布时间:2021-06-11
我正在尝试找到一种为某些用户输入创建弹出屏幕的方法,其中包括单选按钮,editText,按钮.我不想开始一项新活动. 什么是好的选择? AlertDialog? Spinner?弹出菜单? 谢谢 AlertDialog对此没
我正在尝试找到一种为某些用户输入创建弹出屏幕的方法,其中包括单选按钮,editText,按钮.我不想开始一项新活动.
什么是好的选择? AlertDialog? Spinner?弹出菜单?
谢谢 AlertDialog对此没问题.您可以声明一个layout.xml文件,其中包含您需要的所有组件,然后对其进行充气并将其设置为对话框的内容.

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot));
    AlertDialog.Builder builder = new AlertDialog.Builder(this)
    .setView(layout);
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
网友评论