自定义Dialog显示布局,位置

布局item




    


布局




    




样式

 


代码

 private void dialogEducation(){

        final AlertDialog builder = new AlertDialog.Builder(this,R.style.Dialog).create(); // 先得到构造器
        builder.show();
        builder.getWindow().setContentView(R.layout.dialog_jianli);
        LayoutInflater factory = LayoutInflater.from(this);
        View view = factory.inflate(R.layout.dialog_jianli, null);
        builder.getWindow().setContentView(view);
        listview= (ListView) view.findViewById(R.id.lv_dialog);
        StringAdapter adapter;
       
            adapter=new StringAdapter(education,this);
       
        listview.setAdapter(adapter);
        Window dialogWindow = builder.getWindow();
        dialogWindow.setGravity( Gravity.BOTTOM);//显示在底部
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.height = (int) (d.getHeight() * 0.5); // 高度设置为屏幕的0.5
        p.width = d.getWidth(); // 宽度设置为屏幕宽
        dialogWindow.setAttributes(p);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView parent, View view, int position, long id) {
                
                    tv_education.setText(education[position]);
                
                builder.dismiss();
            }
        });
    }

解决自定义Dialog不能弹出软件盘

 builder.getWindow().clearFlags(
                WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);


自定义Dialog显示布局,位置_第1张图片


你可能感兴趣的:(组件,云宽项目)