在底部显示操作按钮Android类库:BottomSheet

jopen 10年前

BottomSheet是一个会在Android ListView的底部工作区域显示一组动作。当点击ListView的某一个项目时会在屏幕底部向上滑出一个包含若干动作的工作区域。

This library works on android 2.1+

Sample Sample Sample Sample

How to use this library

  • Download this library, import to your IDE (eclipse...) as a library project.
  • Using Gradle (will be available soon)
    compile 'com.cocosw:bottomsheet:0.+@aar' 

API

  • Define actions in menu xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">      <item android:id="@+id/share" android:title="@string/share" android:icon="@drawable/perm_group_messages"/>      <item android:id="@+id/upload" android:title="@string/upload" android:icon="@drawable/perm_group_system_clock"/>      <item android:id="@+id/call" android:title="@string/call" android:icon="@drawable/perm_group_phone_calls"/>      <divider/>      <item android:id="@+id/help" android:title="@string/help" android:icon="@drawable/perm_group_system_tools"/>  </menu>
  • Call it just like you call a dialog
new BottomSheet.Builder(this).title("title").sheet(R.menu.list).listener(new DialogInterface.OnClickListener() {                      @Override                      public void onClick(DialogInterface dialog, int which) {                          switch (which) {                              case R.id.help:                                  q.toast("Help me!");                                  break;                          }                      }                  }).show();
  • You can also add action items in builder.

Style

  • Invoke darkTheme() to show build-in dark theme
  • Define your style in your application, and call bottomsheet by using new BottomSheet.Builder(this,R.style.BottomSheet_StyleDialog)....
    <style name="BottomSheet.StyleDialog" parent="BottomSheet.Dialog">          <item name="android:backgroundDimAmount">0.5</item>          <item name="android:windowAnimationStyle">@style/BottomSheet.Animation</item>          <item name="android:textColorPrimary">#DDffffff</item>          <item name="android:textColorSecondary">#8Affffff</item>          <item name="android:textColorHint">#42ffffff</item>          <item name="dialogBackground">@color/abc_search_url_text_normal</item>          <item name="listSelector">@drawable/abc_list_selector_holo_light</item>          <item name="drawSelectorOnTop">false</item>          <item name="dividerColor">@color/abc_search_url_text_pressed</item>      </style>
  • Set bottomesheet style in your activity theme
    <style name="StyleTheme" parent="Theme.AppCompat">          <item name="bottomSheetStyle">@style/BottomSheet.StyleDialog</item>      </style>

项目主页:http://www.open-open.com/lib/view/home/1413858534247