Commit fe422d1a by YKai

feat:键盘事件处理

parent 1f960adc
......@@ -8,6 +8,7 @@ import android.os.Handler
import android.text.Editable
import android.text.TextUtils
import android.text.TextWatcher
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
......@@ -114,7 +115,7 @@ class QuestionInformationView(
cl_input.visibility = VISIBLE
tv_problem.visibility = GONE
hsv_problem_tips.visibility = VISIBLE
et_input_problem.hint="请简单描述遇到的问题……\n\n\n"
et_input_problem.hint = "请简单描述遇到的问题……\n\n\n"
// 打开软件盘
showInputMethod(et_input_problem)
// 滚动到底部
......@@ -157,7 +158,7 @@ class QuestionInformationView(
if (questionsBean != null) {
//还有下一题
questionMultiItem2.questionsBean = questionsBean
if ("radio" == questionsBean?.type) {
if ("radio" == questionsBean.type) {
questionMultiItem2.viewType = 3
} else {
questionMultiItem2.viewType = 4
......@@ -178,7 +179,7 @@ class QuestionInformationView(
cl_input.visibility = VISIBLE
tv_problem.visibility = GONE
hsv_problem_tips.visibility = VISIBLE
et_input_problem.hint="请简单描述遇到的问题……\n\n\n"
et_input_problem.hint = "请简单描述遇到的问题……\n\n\n"
// 打开软件盘
showInputMethod(et_input_problem)
// 滚动到底部
......@@ -199,10 +200,10 @@ class QuestionInformationView(
hsv_problem_tips.visibility = GONE
var problem = "已选:"
list?.forEach {
problem+="# "+it?.name
problem += "# " + it?.name
}
tv_problem.text = problem
et_input_problem.hint="请输入其他事件......"
et_input_problem.hint = "请输入其他事件......"
// 打开软件盘
showInputMethod(et_input_problem)
// 滚动到底部
......@@ -215,6 +216,7 @@ class QuestionInformationView(
}
@SuppressLint("ClickableViewAccessibility")
@RequiresApi(Build.VERSION_CODES.N)
fun setData(questionInfo: QuestionsInfoBean) {
mQuestionBean = questionInfo
......@@ -306,6 +308,25 @@ class QuestionInformationView(
override fun keyBoardHide(height: Int) {
}
})
recycle.setOnTouchListener { _: View?, event: MotionEvent ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
// 手势按下空白处的时候检测软件盘是否弹出
if (isShouldHideInput(et_input_problem, event)) {
hideInputMethod(et_input_problem)
}
true
}
MotionEvent.ACTION_CANCEL, MotionEvent.ACTION_UP -> {
false
}
else -> {
false
}
}
}
}
......@@ -341,4 +362,25 @@ class QuestionInformationView(
dialog!!.show()
}
}
/**
* 判断软键盘是否需要隐藏
* @param v
* @param event
* @return
*/
private fun isShouldHideInput(v: View?, event: MotionEvent): Boolean {
if (v != null && v is EditText) {
val leftTop = intArrayOf(0, 0)
//获取输入框当前的location位置
v.getLocationInWindow(leftTop)
val left = leftTop[0]
val top = leftTop[1]
val bottom = top + v.getHeight()
val right = left + v.getWidth()
return !(event.x > left && event.x < right && event.y > top && event.y < bottom)
}
return false
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment