/**
* 初始化dialog
*/
private void showDialog() {
Dialog dialog =new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.popu_comment);
Window dialogWindow = dialog.getWindow();
dialogWindow.setGravity(Gravity.BOTTOM);
dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
dialogWindow.setAttributes(lp);
dialog.show();
//查找控件
EditText edComment = dialog.findViewById(R.id.ed_comment);
TextView btnFaBu = dialog.findViewById(R.id.btn_fabu_pl);
btnFaBu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
//提交之后要讲str清空
str ="";
//展示框复原
tvContent.setText("请输入您的评论内容");
}
});
//判断有没有编辑过评论内容 如果编辑过就在显示出来
if (!TextUtils.isEmpty(str)) {
edComment.setText(str);
edComment.setSelection(str.length());//将光标移至文字末尾
}
//添加监听
edComment.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
str =edComment.getText().toString();
tvContent.setText(str);
}
});
showSoft();
dismissSofo(dialog);
}