您的位置:首页 > 运维架构

popupwindow弹出的editTextView

2017-07-13 18:59 441 查看
public void getCommentView(final Activity context, View view, final CommentResult commentResult) {
liveCommentResult = commentResult;
if (commentView == null) {
commentView = context.getLayoutInflater().inflate(R.layout.comment_question, null);
}
if (commentPopup == null) {
// 创建一个PopuWidow对象
commentPopup = new PopupWindow(commentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
}
// 设置动画 commentPopup.setAnimationStyle(R.style.popWindow_animation_in2out);
// 使其聚集 ,要想监听菜单里控件的事件就必须要调用此方法
commentPopup.setFocusable(true);
// 设置允许在外点击消失
commentPopup.setOutsideTouchable(true);
// 设置背景,这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
commentPopup.setBackgroundDrawable(new BitmapDrawable());
//必须加这两行,不然不会显示在键盘上方
commentPopup.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
commentPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
// PopupWindow的显示及位置设置
commentPopup.showAtLocation(view, Gravity.BOTTOM, 0, 0);
comment_text = (EditText) commentView.findViewById(R.id.comment_text);
TextView send_comment = (TextView) commentView.findViewById(R.id.send_comment);

comment_text.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {

}

@Override
public void afterTextChanged(Editable s) {
if (s.length() > 0) {
send_comment.setSelected(true);
send_comment.setEnabled(true);
} else {
send_comment.setSelected(false);
send_comment.setEnabled(false);
}
}
});
//这是布局中发送按钮的监听
send_comment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String comment = comment_text.getText().toString();
if (!TextUtils.isEmpty(comment)) {
if (TextUtils.isEmpty(comment.trim())) {
send_comment.setEnabled(false);
} else {
send_comment.setEnabled(true);
//把数据传出去
liveCommentResult.onResult(true, comment);
//关闭popup
commentPopup.dismiss();
}
Toast.makeText(getContext(), getResources().getString(R.string.comment_is_none), Toast.LENGTH_SHORT).show();
}
}
});
//设置popup关闭时要做的操作
commentPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
hideKeyboard(comment_text);
comment_text.setText("");
}
});
//显示软键盘
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//此方法就不提供了,网上一大推
showSoftKeyboard();
}
}, 200);
//显示键盘
}

/**
* 发送评论回调
*/
public interface CommentResult {
void onResult(boolean confirmed, String comment);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐