适配部分机型还会出现输入框被键盘挡住问题

This commit is contained in:
yezhiqiu
2026-04-24 10:29:15 +08:00
parent fa5b707c22
commit 505a0414b8
12 changed files with 81 additions and 42 deletions

View File

@@ -30,7 +30,7 @@ android {
targetSdkVersion 35
versionCode 2202
// versionName "2.2.2"
versionName "2.2.2-Beta6"
versionName "2.2.2-Beta7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

@@ -385,7 +385,8 @@
<activity
android:name=".ui.activity.device.wifi.EditWifiPowerZoneActivity"
android:exported="false"
android:screenOrientation="portrait" />
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".ui.activity.map.LiveActivityV3"
android:exported="false"

View File

@@ -166,12 +166,11 @@ class SubscriptionHistoryAdapter(
val cTimeMillis = System.currentTimeMillis()
val endTime = if (item.refundTime == 0L) item.endTime else item.refundTime
val expiredTime = endTime * 1000 - cTimeMillis
val state =
if (item.enabled == ConstantInt.Type0 || (item.subscriptionStatus == ConstantInt.Close && expiredTime <= 0)) {
context.getString(R.string.txt_expired)
} else {
context.getString(R.string.txt_active)
}
val state = if (item.enabled == ConstantInt.Type0 || (expiredTime <= 0)) {
context.getString(R.string.txt_expired)
} else {
context.getString(R.string.txt_active)
}
holder.setText(R.id.tv_subscription_history_subscription_state, state)
holder.getView<TextView>(R.id.tv_subscription_history_annual_care).apply {

View File

@@ -86,8 +86,8 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
// 监听因输入框弹出,遮挡输入框,界面移动,需要移动的view
private var mTranslateView: View? = null
/*****************************监听软键盘弹出,输入框上移start************************************/
private var isKeyboardTranslate = true
/*****************************监听软键盘弹出,输入框上移 ************************************/
var isKeyboardTranslate = true
//是否需要适配底部EdgeToEdge
var isEdgeToEdgeAdapterNavigationBars = true
@@ -231,16 +231,25 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
/**
* 监听键盘弹出和隐藏,解决键盘弹出挡住输入框的问题
*/
fun setListenKeyboardChange(windowTranslateY: Int = 500, view: View = window.decorView) {
fun setListenKeyboardChange(
windowTranslateY: Int = 500,
view: View = window.decorView,
methodType: Int = ConstantInt.Type0
) {
val metrics = getResources().displayMetrics
val screenWidth = metrics.widthPixels
// val screenHeight = metrics.heightPixels
val scaleFactor = screenWidth / 1080 // 假设 1080 是设计宽度
window.decorView.viewTreeObserver.addOnGlobalLayoutListener {
onLayoutChange(view, windowTranslateY * scaleFactor)
view.viewTreeObserver.addOnGlobalLayoutListener {
if (methodType == ConstantInt.Type0) {
onLayoutChange(view, windowTranslateY * scaleFactor)
} else {
onGlobalLayoutChange(view, windowTranslateY * scaleFactor)
}
}
}
/**
* 设置其他包含的view点击。隐藏软键盘如ScrollView
*/
@@ -834,10 +843,10 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
private fun onLayoutChange(translateView: View, translateY: Int) {
mTranslateView = translateView
//获取当前屏幕内容的高度
val screenHeight = window.decorView.height
val screenHeight = translateView.height
//获取View可见区域的bottom
val rect = Rect()
window.decorView.getWindowVisibleDisplayFrame(rect)
translateView.getWindowVisibleDisplayFrame(rect)
if (screenHeight - getNavigatorBarHeight() > rect.bottom) {
// 获取按钮的左上角按钮高度为40dp
// val location = IntArray(2)
@@ -845,7 +854,7 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
// val bottom = location[1] + resources.getDimensionPixelSize(R.dimen.dp_80)
//// 如果按钮被覆盖,移动整个界面向上移动
// if (bottom > rect.bottom) {
// window.decorView.scrollBy(0, bottom - rect.bottom)
// translateView.scrollBy(0, bottom - rect.bottom)
// isKeyboardTranslate = true
// }
if (!isKeyboardTranslate) {
@@ -864,5 +873,28 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
hideSoftKeyboardCallback()
}
}
private fun onGlobalLayoutChange(translateView: View, translateY: Int) {
mTranslateView = translateView
val r = Rect()
translateView.getWindowVisibleDisplayFrame(r)
val heightDiff = translateView.getRootView().height - (r.bottom - r.top)
if (heightDiff > 200) { // 如果高度差大于200说明键盘是弹出的
// 进行布局调整
if (!isKeyboardTranslate) {
//移动到指定位置点坐标
translateView.scrollBy(0, translateY)
isKeyboardTranslate = true
}
LogUtil.e("如果高度差大于200说明键盘是弹出的")
showSoftKeyboardCallback()
} else {
// 键盘隐藏,恢复布局
isKeyboardTranslate = false
LogUtil.e("键盘隐藏,恢复布局")
translateView.scrollTo(0, 0)
hideSoftKeyboardCallback()
}
}
/*****************************监听软键盘弹出输入框上移end************************************/
}

View File

@@ -7,6 +7,7 @@ import coil.transform.BlurTransformation
import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.databinding.ActivityAddEmailValidBinding
import com.abbidot.tracker.ui.fragment.account.EmailValidFragment
@@ -31,7 +32,7 @@ open class AddEmailValidActivity :
ivForgotPasswordV2BlurBg.load(R.drawable.icon_login_v2_bg) {
transformations(BlurTransformation(mContext, 25f))
}
setListenKeyboardChange(750)
setListenKeyboardChange(750, methodType = ConstantInt.Type1)
}
switchFragment(mIndex)

View File

@@ -181,6 +181,7 @@ open class AddAndEditFencesZoneBaseActivity :
rlAddEditFencesZoneInfoLayout.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> {
hideInputMethod(v)
oldY = event.y
}
@@ -188,10 +189,12 @@ open class AddAndEditFencesZoneBaseActivity :
}
MotionEvent.ACTION_UP -> {
if (event.y - oldY > slideDis) {
downLayout()
} else if (event.y - oldY < -slideDis) {
slideUpLayout()
if (!isKeyboardTranslate) {
if (event.y - oldY > slideDis) {
downLayout()
} else if (event.y - oldY < -slideDis) {
slideUpLayout()
}
}
}
}
@@ -203,7 +206,7 @@ open class AddAndEditFencesZoneBaseActivity :
}
}
setListenKeyboardChange()
setListenKeyboardChange(methodType = ConstantInt.Type1)
setFenceName()
}

View File

@@ -118,7 +118,7 @@ class EditWifiPowerZoneActivity :
add(R.id.fc_edit_power_zone_map_fragment, mFragment)
}
setListenKeyboardChange(600)
// setListenKeyboardChange(600)
if (null != mBleTrackDeviceBean) {
ilEditPowerZoneBluetoothTips.trbBleConnectState.let {

View File

@@ -88,19 +88,18 @@ class FeedbackActivity : BaseActivity<ActivityFeedbackBinding>(ActivityFeedbackB
setOnClickListenerViews(btnSubmitSettingFeedback, llSelectImageBtnLayout)
setViewClickHideInputMethod(llSettingFeedbackLayout)
setListenKeyboardChange(300, svSettingFeedbackScroll)
}
setListenKeyboardChange(300)
}
//添加图片后,再输入邮箱,输入框被挡住
override fun showSoftKeyboardCallback() {
mViewBinding.apply {
if (ilFeedbackPhoneLayout.etInputContent.hasFocus()) {
if (mUploadImageUrlList.size > 0) svSettingFeedbackScroll.postDelayed({
if (mUploadImageUrlList.size > 0) svSettingFeedbackScroll.postDelayed({
svSettingFeedbackScroll.scrollY = 1000
}, 400)
else svSettingFeedbackScroll.scrollY = 600
else svSettingFeedbackScroll.scrollY = 500
}
}
}

View File

@@ -156,7 +156,7 @@ class PetProfileActivity :
setPetData()
mPetViewModel.getPetLabels(this)
setListenKeyboardChange()
setListenKeyboardChange(methodType = ConstantInt.Type1)
}
override fun liveDataObserve() {
@@ -572,7 +572,8 @@ class PetProfileActivity :
override fun onClick(v: View?) {
mViewBinding.apply {
when (v!!) {
hideInputMethod(v!!)
when (v) {
ilPetProfileHeadLayout.ilPetProfileHead.appHeadImage -> ViewUtil.instance.goSelectPhoto(
this@PetProfileActivity, ResultCode.ResultCode_1
)

View File

@@ -71,7 +71,7 @@ abstract class BaseGoogleMapFragment :
BaseFragment<FragmentGoogleMapBinding>(FragmentGoogleMapBinding::inflate), OnMapReadyCallback {
var mGoogleMap: GoogleMap? = null
private lateinit var mGoogleMapView: MapView
private var mGoogleMapView: MapView? = null
/**地图样式类型:卫星/标准
* GoogleMap.MAP_TYPE_NONE 不显示地图
@@ -142,7 +142,7 @@ abstract class BaseGoogleMapFragment :
camera(position)
}
mGoogleMapView = MapView(this.requireActivity(), options)
mGoogleMapView.onCreate(mapViewBundle)
mGoogleMapView?.onCreate(mapViewBundle)
mViewBinding.root.addView(mGoogleMapView)
return mViewBinding.root
@@ -150,12 +150,12 @@ abstract class BaseGoogleMapFragment :
override fun initData() {
super.initData()
mGoogleMapView.getMapAsync(this)
mGoogleMapView?.getMapAsync(this)
}
override fun onResume() {
super.onResume()
mGoogleMapView.onResume()
mGoogleMapView?.onResume()
mGoogleMap?.apply {
val mapTypeSp = Util.getMapTypeSp()
@@ -169,7 +169,7 @@ abstract class BaseGoogleMapFragment :
override fun onStart() {
super.onStart()
mGoogleMapView.onStart()
mGoogleMapView?.onStart()
}
override fun onSaveInstanceState(outState: Bundle) {
@@ -180,18 +180,18 @@ abstract class BaseGoogleMapFragment :
mapViewBundle = Bundle()
outState.putBundle(mMapviewBundleKey, mapViewBundle)
}
mGoogleMapView.onSaveInstanceState(mapViewBundle)
mGoogleMapView?.onSaveInstanceState(mapViewBundle)
}
override fun onPause() {
super.onPause()
mGoogleMapView.onPause()
mGoogleMapView?.onPause()
}
override fun onLowMemory() {
super.onLowMemory()
mGoogleMapView.onLowMemory()
mGoogleMapView?.onLowMemory()
}
/**
@@ -322,7 +322,8 @@ abstract class BaseGoogleMapFragment :
}
}
}
else->{
else -> {
}
@@ -478,7 +479,7 @@ abstract class BaseGoogleMapFragment :
// } else {
// onRefreshPetCurrentLocationOk(mGoogleMap!!)
// }
mGoogleMapView.postDelayed({
mGoogleMapView?.postDelayed({
onRefreshPetCurrentLocationOk(mGoogleMap!!)
}, 500)
}
@@ -1249,13 +1250,13 @@ abstract class BaseGoogleMapFragment :
override fun onStop() {
super.onStop()
mCancellationTokenSource?.cancel()
mGoogleMapView.onStop()
mGoogleMapView?.onStop()
}
override fun onDestroy() {
super.onDestroy()
mPetHeadIconBitmap?.recycle()
mGoogleMapView.onDestroy()
mGoogleMapView?.onDestroy()
}
}

View File

@@ -65,6 +65,8 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/shape20_white_half_bottom_bg"
android:clickable="true"
android:focusable="true"
android:paddingHorizontal="@dimen/dp_22"
android:paddingBottom="@dimen/dp_22">

View File

@@ -20,7 +20,7 @@
android:id="@+id/ll_setting_feedback_layout"
style="@style/root_layout_style"
android:layout_marginHorizontal="@dimen/dp_16"
android:layout_marginVertical="@dimen/dp_18"
android:layout_marginBottom="@dimen/dp_18"
android:fitsSystemWindows="true"
android:orientation="vertical">