forked from princekin-f/EasyFloat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ea941b
commit 3fdc062
Showing
8 changed files
with
152 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
easyfloat/src/main/java/com/lzf/easyfloat/utils/InputMethodUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.lzf.easyfloat.utils | ||
|
||
import android.content.Context.INPUT_METHOD_SERVICE | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.view.WindowManager | ||
import android.view.inputmethod.InputMethodManager | ||
import android.widget.EditText | ||
import com.lzf.easyfloat.service.FloatService | ||
|
||
/** | ||
* @author: liuzhenfeng | ||
* @function: 软键盘工具类 | ||
* 1,解决系统浮窗内的EditText,无法弹起软键盘的问题; | ||
* 2,暂未提供软键盘关闭的监听,需要使用者自行处理,希望各位大佬共同提供解决方案。 | ||
* @date: 2019-08-17 11:11 | ||
*/ | ||
object InputMethodUtils { | ||
|
||
/** | ||
* 让系统浮窗获取焦点,并打开软键盘 | ||
*/ | ||
@JvmStatic | ||
@JvmOverloads | ||
fun openInputMethod(editText: EditText, tag: String? = null) { | ||
FloatService.floatMap[tag ?: FloatService.DEFAULT_TAG]?.run { | ||
// 更改flags,并刷新布局,让系统浮窗获取焦点 | ||
params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | ||
windowManager.updateViewLayout(frameLayout, params) | ||
} | ||
|
||
Handler(Looper.getMainLooper()).postDelayed({ | ||
// 打开软键盘 | ||
val inputManager = | ||
editText.context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager? | ||
inputManager?.showSoftInput(editText, 0) | ||
}, 100) | ||
} | ||
|
||
/** | ||
* 当软键盘关闭时,调用此方法,移除系统浮窗的焦点,不然系统返回键无效 | ||
*/ | ||
@JvmStatic | ||
@JvmOverloads | ||
fun closedInputMethod(tag: String? = null) { | ||
FloatService.floatMap[tag ?: FloatService.DEFAULT_TAG]?.run { | ||
params.flags = | ||
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | ||
windowManager.updateViewLayout(frameLayout, params) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="200dp" | ||
android:layout_height="wrap_content" | ||
android:background="@color/translucent" | ||
android:gravity="center_horizontal" | ||
android:orientation="vertical" | ||
android:padding="10dp"> | ||
|
||
<EditText | ||
android:id="@+id/editText" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" /> | ||
|
||
<TextView | ||
android:id="@+id/tvImmClosed" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="10dp" | ||
android:text="软键盘已关闭" | ||
android:textColor="@color/white" /> | ||
|
||
<TextView | ||
android:id="@+id/tvCloseFloat" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:padding="10dp" | ||
android:text="关闭浮窗" | ||
android:textColor="@color/white" /> | ||
|
||
</LinearLayout> |