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

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 targetSdkVersion 35
versionCode 2202 versionCode 2202
// versionName "2.2.2" // versionName "2.2.2"
versionName "2.2.2-Beta6" versionName "2.2.2-Beta7"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

View File

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

View File

@@ -166,8 +166,7 @@ class SubscriptionHistoryAdapter(
val cTimeMillis = System.currentTimeMillis() val cTimeMillis = System.currentTimeMillis()
val endTime = if (item.refundTime == 0L) item.endTime else item.refundTime val endTime = if (item.refundTime == 0L) item.endTime else item.refundTime
val expiredTime = endTime * 1000 - cTimeMillis val expiredTime = endTime * 1000 - cTimeMillis
val state = val state = if (item.enabled == ConstantInt.Type0 || (expiredTime <= 0)) {
if (item.enabled == ConstantInt.Type0 || (item.subscriptionStatus == ConstantInt.Close && expiredTime <= 0)) {
context.getString(R.string.txt_expired) context.getString(R.string.txt_expired)
} else { } else {
context.getString(R.string.txt_active) context.getString(R.string.txt_active)

View File

@@ -86,8 +86,8 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
// 监听因输入框弹出,遮挡输入框,界面移动,需要移动的view // 监听因输入框弹出,遮挡输入框,界面移动,需要移动的view
private var mTranslateView: View? = null private var mTranslateView: View? = null
/*****************************监听软键盘弹出,输入框上移start************************************/ /*****************************监听软键盘弹出,输入框上移 ************************************/
private var isKeyboardTranslate = true var isKeyboardTranslate = true
//是否需要适配底部EdgeToEdge //是否需要适配底部EdgeToEdge
var isEdgeToEdgeAdapterNavigationBars = true var isEdgeToEdgeAdapterNavigationBars = true
@@ -231,15 +231,24 @@ 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 metrics = getResources().displayMetrics
val screenWidth = metrics.widthPixels val screenWidth = metrics.widthPixels
// val screenHeight = metrics.heightPixels // val screenHeight = metrics.heightPixels
val scaleFactor = screenWidth / 1080 // 假设 1080 是设计宽度 val scaleFactor = screenWidth / 1080 // 假设 1080 是设计宽度
window.decorView.viewTreeObserver.addOnGlobalLayoutListener { view.viewTreeObserver.addOnGlobalLayoutListener {
if (methodType == ConstantInt.Type0) {
onLayoutChange(view, windowTranslateY * scaleFactor) onLayoutChange(view, windowTranslateY * scaleFactor)
} else {
onGlobalLayoutChange(view, windowTranslateY * scaleFactor)
} }
} }
}
/** /**
* 设置其他包含的view点击。隐藏软键盘如ScrollView * 设置其他包含的view点击。隐藏软键盘如ScrollView
@@ -834,10 +843,10 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
private fun onLayoutChange(translateView: View, translateY: Int) { private fun onLayoutChange(translateView: View, translateY: Int) {
mTranslateView = translateView mTranslateView = translateView
//获取当前屏幕内容的高度 //获取当前屏幕内容的高度
val screenHeight = window.decorView.height val screenHeight = translateView.height
//获取View可见区域的bottom //获取View可见区域的bottom
val rect = Rect() val rect = Rect()
window.decorView.getWindowVisibleDisplayFrame(rect) translateView.getWindowVisibleDisplayFrame(rect)
if (screenHeight - getNavigatorBarHeight() > rect.bottom) { if (screenHeight - getNavigatorBarHeight() > rect.bottom) {
// 获取按钮的左上角按钮高度为40dp // 获取按钮的左上角按钮高度为40dp
// val location = IntArray(2) // 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) // val bottom = location[1] + resources.getDimensionPixelSize(R.dimen.dp_80)
//// 如果按钮被覆盖,移动整个界面向上移动 //// 如果按钮被覆盖,移动整个界面向上移动
// if (bottom > rect.bottom) { // if (bottom > rect.bottom) {
// window.decorView.scrollBy(0, bottom - rect.bottom) // translateView.scrollBy(0, bottom - rect.bottom)
// isKeyboardTranslate = true // isKeyboardTranslate = true
// } // }
if (!isKeyboardTranslate) { if (!isKeyboardTranslate) {
@@ -864,5 +873,28 @@ abstract class BaseActivity<T : ViewBinding>(val inflater: (inflater: LayoutInfl
hideSoftKeyboardCallback() 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************************************/ /*****************************监听软键盘弹出输入框上移end************************************/
} }

View File

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

View File

@@ -181,6 +181,7 @@ open class AddAndEditFencesZoneBaseActivity :
rlAddEditFencesZoneInfoLayout.setOnTouchListener { v, event -> rlAddEditFencesZoneInfoLayout.setOnTouchListener { v, event ->
when (event.action) { when (event.action) {
MotionEvent.ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> {
hideInputMethod(v)
oldY = event.y oldY = event.y
} }
@@ -188,6 +189,7 @@ open class AddAndEditFencesZoneBaseActivity :
} }
MotionEvent.ACTION_UP -> { MotionEvent.ACTION_UP -> {
if (!isKeyboardTranslate) {
if (event.y - oldY > slideDis) { if (event.y - oldY > slideDis) {
downLayout() downLayout()
} else if (event.y - oldY < -slideDis) { } else if (event.y - oldY < -slideDis) {
@@ -195,6 +197,7 @@ open class AddAndEditFencesZoneBaseActivity :
} }
} }
} }
}
false false
} }
//监听布局变化 //监听布局变化
@@ -203,7 +206,7 @@ open class AddAndEditFencesZoneBaseActivity :
} }
} }
setListenKeyboardChange() setListenKeyboardChange(methodType = ConstantInt.Type1)
setFenceName() setFenceName()
} }

View File

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

View File

@@ -88,9 +88,8 @@ class FeedbackActivity : BaseActivity<ActivityFeedbackBinding>(ActivityFeedbackB
setOnClickListenerViews(btnSubmitSettingFeedback, llSelectImageBtnLayout) setOnClickListenerViews(btnSubmitSettingFeedback, llSelectImageBtnLayout)
setViewClickHideInputMethod(llSettingFeedbackLayout) setViewClickHideInputMethod(llSettingFeedbackLayout)
setListenKeyboardChange(300, svSettingFeedbackScroll)
} }
setListenKeyboardChange(300)
} }
//添加图片后,再输入邮箱,输入框被挡住 //添加图片后,再输入邮箱,输入框被挡住
@@ -100,7 +99,7 @@ class FeedbackActivity : BaseActivity<ActivityFeedbackBinding>(ActivityFeedbackB
if (mUploadImageUrlList.size > 0) svSettingFeedbackScroll.postDelayed({ if (mUploadImageUrlList.size > 0) svSettingFeedbackScroll.postDelayed({
svSettingFeedbackScroll.scrollY = 1000 svSettingFeedbackScroll.scrollY = 1000
}, 400) }, 400)
else svSettingFeedbackScroll.scrollY = 600 else svSettingFeedbackScroll.scrollY = 500
} }
} }
} }

View File

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

View File

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

View File

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

View File

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