简单地说,你可以使用Material-Design
个图书馆.Standard Bottom Sheet
就是你想要的.以下是一个小的用户界面示例:
*请注意,它必须在CoordinatorLayout
中
<androidx.coordinatorlayout.widget.CoordinatorLayout
...>
<FrameLayout
android:id="@+id/standard_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="?attr/bottomSheetStyle"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<!-- Bottom sheet contents. -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
.../>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/supporting_text"
.../>
<Button
android:id="@+id/bottomsheet_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/action"
.../>
并且您必须设置Peek Height并设置其行为,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Base.Theme.App" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="bottomSheetStyle">@style/StandardBottomSheet</item>
</style>
<style name="StandardBottomSheet">
<item name="backgroundTint">@android:color/white</item>
<item name="android:elevation">8dp</item>
<item name="elevation">8dp</item>
<item name="behavior_hideable">true</item>
<item name="behavior_draggable">true</item>
<item name="behavior_skipCollapsed">false</item>
<item name="behavior_fitToContents">true</item>
<item name="behavior_peekHeight">176dp</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden</item>
</style>
</resources>