MainActivity
Код: Выделить всё
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
val button = findViewById(R.id.button)
button.setOnClickListener {
showBottomSheet()
}
}
private fun showBottomSheet() {
val dialog = BottomSheetDialog(this, R.style.Widget_BottomSheetDialog)
dialog.apply {
dialog.setContentView(BottomSheetView(this@MainActivity))
behavior.skipCollapsed = true
behavior.state = BottomSheetBehavior.STATE_EXPANDED
show()
}
}
}
Код: Выделить всё
class BottomSheetView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr){
private val editText: EditText
init {
LayoutInflater.from(context).inflate(R.layout.bottom_sheet, this, true)
editText = findViewById(R.id.editText)
editText.requestFocus()
val imm = context.getSystemService(InputMethodManager::class.java)
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
}
Код: Выделить всё
Код: Выделить всё
@style/CustomBottomSheet
false
@android:color/transparent
Постановка проблемы:
Когда я открываю лист с помощью клавиатуры, между клавиатурой и нижним листом остается пустое пространство. Как мне поступить, если я хочу, чтобы нижний лист и клавиатура открывались одновременно?
Проблема GIF
Подробнее здесь: https://stackoverflow.com/questions/782 ... keyboard-w
Мобильная версия