Запись экрана
TestAvtivity.kt
class TestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
val behavior = BottomSheetBehavior.from(bottomSheet)
bottomSheet.post {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}
startBtn.setOnClickListener {
val intent = Intent(this, SearchTestActivity::class.java)
startActivity(intent)
}
}
}
activity_test. xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/startBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="OPEN SAERCH" />
</FrameLayout>
<androidx.core.widget.NestedScrollView
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="bottom"
android:background="@color/light_green_900"
app:layout_behavior="@string/bottom_sheet_behavior">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Title"
android:layout_gravity="center"
android:text="BottomSheet"/>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
SearchTestActivity.kt
class SearchTestActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_search_test)
finishBtn.setOnClickListener { finish() }
}
}
Когда я завершил sh действие с помощью клавиатуры (см. Запись экрана), нижняя таблица исчезла, и когда-то нижняя таблица исчезла сразу после развертывания , Я не могу снова появиться, как ее решить, спасибо.
Изменить 1 Я решаю это путем набора STATE_EXPANDED
в onResume()
и набора STATE_HIDDEN
в onPaues()
class TestActivity : AppCompatActivity() {
private lateinit var behavior: BottomSheetBehavior<*>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_test)
behavior = BottomSheetBehavior.from(bottomSheet)
behavior.isHideable = true
behavior.state = BottomSheetBehavior.STATE_HIDDEN
startBtn.setOnClickListener {
val intent = Intent(this, SearchTestActivity::class.java)
startActivity(intent)
}
}
override fun onResume() {
super.onResume()
if (behavior.state == BottomSheetBehavior.STATE_HIDDEN) {
bottomSheet.post {
behavior.state = BottomSheetBehavior.STATE_EXPANDED
}
}
}
override fun onPause() {
super.onPause()
behavior.state = BottomSheetBehavior.STATE_HIDDEN
}
}