|
|
@@ -4,6 +4,8 @@ import android.content.ClipboardManager
|
|
|
import android.content.Context
|
|
|
import android.content.Context.CLIPBOARD_SERVICE
|
|
|
import android.content.Intent
|
|
|
+import android.inputmethodservice.InputMethodService
|
|
|
+import android.os.Build
|
|
|
import android.provider.Settings
|
|
|
import android.view.inputmethod.EditorInfo
|
|
|
import android.view.inputmethod.InputConnection
|
|
|
@@ -16,6 +18,15 @@ import android.widget.EditText
|
|
|
class InputMethodUtil private constructor() {
|
|
|
companion object {
|
|
|
/**
|
|
|
+ * 显示输入法选择器
|
|
|
+ */
|
|
|
+ fun showInputMethodPicker(context: Context) {
|
|
|
+ val inputMethodManager =
|
|
|
+ context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
+ inputMethodManager.showInputMethodPicker()
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 打开输入法设置
|
|
|
*/
|
|
|
fun openInputMethodSettings(context: Context) {
|
|
|
@@ -99,8 +110,25 @@ class InputMethodUtil private constructor() {
|
|
|
/**
|
|
|
* 自定义键盘,点击发送按钮,触发发送行为
|
|
|
*/
|
|
|
- fun clickSendBtn(currentInputConnection: InputConnection) {
|
|
|
- currentInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND)
|
|
|
+ fun clickSendBtn(inputMethodService: InputMethodService) {
|
|
|
+ inputMethodService.currentInputConnection.performEditorAction(EditorInfo.IME_ACTION_SEND)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保持输入法显示
|
|
|
+ */
|
|
|
+ fun keepKeyboardShow(inputMethodService: InputMethodService) {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
+ inputMethodService.requestShowSelf(0)
|
|
|
+ } else {
|
|
|
+ // 对于较低版本,尝试通过InputMethodManager重新显示键盘
|
|
|
+ val imm =
|
|
|
+ inputMethodService.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
+ val view = inputMethodService.window.window?.decorView
|
|
|
+ view?.post {
|
|
|
+ imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|