У меня возникла проблема, когда клавиатура делает это так, что нижний лист отображается только наполовину (см. Первое фото). Мне бы хотелось, чтобы, когда пользователь нажимает на панель поиска, нижний лист всегда расширялся до верхней части страницы, а затем присутствовала клавиатура (см. Фото 2). Я думал, что проблема в STATE_EXPANDED и как-то отключает клавиатуру, но это не работает. Любая помощь будет оценена.
class CustomBottomSheetBehavior<T : View>(private val context: Context, attrs: AttributeSet) :
BottomSheetBehavior<T>(context, attrs), GestureDetector.OnGestureListener {
private lateinit var customBottomSheetCallback: CustomBottomSheetCallback<T>
private val gestureDetector = GestureDetector(context, this)
interface BottomSheetStateChangeListener {
fun changeBottomSheetState(state: Int)
}
fun setupCallback(listener: BottomSheetStateChangeListener) {
customBottomSheetCallback = CustomBottomSheetCallback(this, listener)
this.setBottomSheetCallback(customBottomSheetCallback)
}
override fun onTouchEvent(parent: CoordinatorLayout, child: T, event: MotionEvent): Boolean {
// gestureDetector.onTouchEvent(event)
return super.onTouchEvent(parent, child, event)
}
override fun onDown(motionEvent: MotionEvent): Boolean {
return false
}
override fun onShowPress(motionEvent: MotionEvent) {
}
override fun onSingleTapUp(motionEvent: MotionEvent): Boolean {
state = STATE_EXPANDED
return false
}
override fun onScroll(
motionEvent: MotionEvent,
motionEvent1: MotionEvent,
v: Float,
v1: Float
): Boolean {
return false
}
override fun onLongPress(motionEvent: MotionEvent) {
}
override fun onFling(
motionEvent: MotionEvent,
motionEvent1: MotionEvent,
v: Float,
v1: Float
): Boolean {
if(motionEvent.y < motionEvent1.y) {
Log.d("onFling", "down swipe")
customBottomSheetCallback.directFling = DirectFling.Down
} else {
Log.d("onFling", "up swipe")
customBottomSheetCallback.directFling = DirectFling.UP
}
return false
}
enum class DirectFling {
UP, Down
}
internal inner class CustomBottomSheetCallback<T : View>(private val bottomSheetBehavior: CustomBottomSheetBehavior<T>, private val listener: BottomSheetStateChangeListener) :
BottomSheetBehavior.BottomSheetCallback() {
// 4(Collapsed) or 3(Expanded) or 6(Half_Expanded)
var preState = 4
var directFling: DirectFling? = null
private var offset: Float = 0.toFloat()
override fun onStateChanged(view: View, state: Int) {
if(state == STATE_SETTLING) {
when(preState) {
STATE_COLLAPSED -> {
if (directFling == DirectFling.UP) {
bottomSheetBehavior.state = STATE_EXPANDED
}
}
STATE_EXPANDED -> {
if (directFling == DirectFling.Down) {
bottomSheetBehavior.state = STATE_COLLAPSED
}
}
}
}
if (state == STATE_COLLAPSED) {
preState = STATE_COLLAPSED
listener.changeBottomSheetState(STATE_HIDDEN)
Log.d("state collapse", "full collapsed")
//Collapse keyboard
val imm = ContextCompat.getSystemService(view.context, InputMethodManager::class.java)
imm?.hideSoftInputFromWindow(view.windowToken, 0)
//Collapse keyboard
}
if(state == STATE_EXPANDED) {
preState = STATE_EXPANDED
listener.changeBottomSheetState(STATE_EXPANDED)
Log.d("state expandedf", "full expanded")
}
}
override fun onSlide(view: View, offset: Float) {
this.offset = offset
}
}
}