正倒计时布局统一消除晃动;原因弹层适配输入法;已完成按钮位置固定;原因文案与暂停原因;科技蓝主色

This commit is contained in:
XIGE
2026-11-28 11:35:03 +08:00
parent 3c641d4fd8
commit 2ad86e2255
12 changed files with 256 additions and 98 deletions

View File

@@ -3,10 +3,12 @@ package com.focusbox.app.ui
import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.view.WindowManager
import com.focusbox.app.R
@@ -18,6 +20,9 @@ import com.focusbox.app.R
*/
open class SheetDialog(context: Context) : Dialog(context, R.style.SheetDialog) {
private var imeRoot: View? = null
private var imeListener: ViewTreeObserver.OnGlobalLayoutListener? = null
init {
window?.apply {
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
@@ -35,6 +40,35 @@ open class SheetDialog(context: Context) : Dialog(context, R.style.SheetDialog)
(view.parent as? View)?.setBackgroundColor(Color.TRANSPARENT)
}
/**
* 让带输入框的弹层跟随软键盘:弹出时整体上移,收起后回到页面底部。
* ADJUST_RESIZE 在部分 EMUI 上不会推动 Dialog 内容,只能自己按可见区域平移。
*/
fun fitOnIme(content: View) {
window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
val root = content.rootView
imeRoot = root
val threshold = (context.resources.displayMetrics.density * 100).toInt()
val screenHeight = context.resources.displayMetrics.heightPixels
val listener = object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
val frame = Rect()
root.getWindowVisibleDisplayFrame(frame)
val keyboard = screenHeight - frame.bottom
content.translationY = if (keyboard > threshold) -keyboard.toFloat() else 0f
}
}
root.viewTreeObserver.addOnGlobalLayoutListener(listener)
imeListener = listener
}
override fun dismiss() {
imeListener?.let { imeRoot?.viewTreeObserver?.removeOnGlobalLayoutListener(it) }
imeListener = null
imeRoot = null
super.dismiss()
}
override fun show() {
super.show()
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)