|
|
@@ -1,6 +1,8 @@
|
|
|
package com.atmob.keyboard_android.ui.popup
|
|
|
|
|
|
import android.annotation.SuppressLint
|
|
|
+import android.graphics.Color
|
|
|
+import android.graphics.drawable.ColorDrawable
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
@@ -22,7 +24,7 @@ import me.drakeet.multitype.MultiTypeAdapter
|
|
|
* 模式切换PopupWindow弹窗
|
|
|
*/
|
|
|
class ModeSwitchPopupWindow() {
|
|
|
- private var popupWindow: PopupWindow? = null
|
|
|
+ private var mPopupWindow: PopupWindow? = null
|
|
|
|
|
|
/**
|
|
|
* 模式切换监听器
|
|
|
@@ -45,7 +47,7 @@ class ModeSwitchPopupWindow() {
|
|
|
|
|
|
val context = anchorView.context
|
|
|
|
|
|
- if (popupWindow == null) {
|
|
|
+ if (mPopupWindow == null) {
|
|
|
val contentView =
|
|
|
LayoutInflater.from(context).inflate(R.layout.popup_mode_switch_attach, null, false)
|
|
|
|
|
|
@@ -92,7 +94,12 @@ class ModeSwitchPopupWindow() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- popupWindow = PopupWindow(
|
|
|
+ contentView.setOnTouchListener { _, event ->
|
|
|
+ // 拦截所有触摸事件,不传递给底层
|
|
|
+ true
|
|
|
+ }
|
|
|
+
|
|
|
+ mPopupWindow = PopupWindow(
|
|
|
contentView,
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
|
@@ -106,6 +113,8 @@ class ModeSwitchPopupWindow() {
|
|
|
inputMethodMode = PopupWindow.INPUT_METHOD_NEEDED
|
|
|
// 设置弹出动画
|
|
|
animationStyle = R.style.PopupAnimation
|
|
|
+ // 透明背景
|
|
|
+ setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -117,7 +126,7 @@ class ModeSwitchPopupWindow() {
|
|
|
val popupX = location[0] - ConvertUtils.dp2px(5f)
|
|
|
val popupY = location[1] - ConvertUtils.dp2px(5f)
|
|
|
|
|
|
- popupWindow?.showAtLocation(
|
|
|
+ mPopupWindow?.showAtLocation(
|
|
|
anchorView,
|
|
|
Gravity.NO_GRAVITY,
|
|
|
popupX,
|
|
|
@@ -129,13 +138,13 @@ class ModeSwitchPopupWindow() {
|
|
|
* 弹窗是否显示中
|
|
|
*/
|
|
|
fun isShowing(): Boolean {
|
|
|
- return popupWindow?.isShowing == true
|
|
|
+ return mPopupWindow?.isShowing == true
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 关闭弹窗
|
|
|
*/
|
|
|
fun dismiss() {
|
|
|
- popupWindow?.dismiss()
|
|
|
+ mPopupWindow?.dismiss()
|
|
|
}
|
|
|
}
|