底部弹窗
final Dialog bgSetDialog = new Dialog(UserMessageActivity.this,R.style.BottomDialogStyle);
//填充对话框的布局
View view1 = LayoutInflater.from(UserMessageActivity.this).inflate(R.layout.bg_set_dialog_delete, null);
//初始化控件
EmojiEditText emojiEditText=view1.findViewById(R.id.input);
TextView textView=view1.findViewById(R.id.delete);
TextView cancel=view1.findViewById(R.id.cancel);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nameNick.setText(emojiEditText.getText().toString());
PreferenceUtil.saveUserNickName(emojiEditText.getText().toString());
BmobUtil.updateMessage();
bgSetDialog.dismiss();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bgSetDialog.dismiss();
}
});
//将布局设置给Dialog
bgSetDialog.setContentView(view1);
//获取当前Activity所在的窗体
Window dialogWindow = bgSetDialog.getWindow();
//设置Dialog从窗体底部弹出
dialogWindow.setGravity( Gravity.BOTTOM);
//获得窗体的属性
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = (int) (UserMessageActivity.this.getWindowManager().getDefaultDisplay().getWidth()*0.95);
lp.y = 60; //设置Dialog距离底部的距离
dialogWindow.setAttributes(lp); //将属性设置给窗体
bgSetDialog.show();//显示对话框
性别选择器弹窗
String[] items={"男","女"};
new AlertDialog.Builder(this)
.setTitle("性别")
.setSingleChoiceItems(items, 2, new DialogInterface.OnClickListener() {//第二个参数是默认数组下标
@Override
public void onClick(DialogInterface dialog, int which) {
if(which==0){
PreferenceUtil.saveUserSex(true);
sex.setText("男");
} else{
PreferenceUtil.saveUserSex(false);
sex.setText("女");
}
BmobUtil.updateMessage();
dialog.dismiss();
}
})
.show();
重构修改,保存一下之前的防止丢失