Quellcode durchsuchen

[feat]键盘插件,配置PopupWindow默认背景

hezihao vor 8 Monaten
Ursprung
Commit
8bb3d3be5e

+ 2 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/page/impl/LoginPageComponent.kt

@@ -39,8 +39,9 @@ class LoginPageComponent @JvmOverloads constructor(
             hide()
         }
         vLoginBtn.click {
-            // 跳转到登录页
+            // 跳转到登录页,并关闭自身
             FlutterBridgeManager.jump2LoginPage()
+            hide()
         }
         setData()
     }

+ 15 - 6
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/ui/popup/ModeSwitchPopupWindow.kt

@@ -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()
     }
 }