一個可以下滑顯示出一個面板的Toolbar。這個library受Drawerlayout的啟發,但有別於Drawerlayout顯示左右抽屜,這個library會提供下拉toolbar顯示一個面板的功
阿新 • • 發佈:2019-02-12
為了使用它你需要把ToolbarPanelLayout作為你的根佈局:
- <com.nikoyuwono.toolbarpanel.ToolbarPanelLayoutxmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/sliding_down_toolbar_layout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- app:panelId="@+id/panel"
- app:toolbarId="@+id/toolbar">
- <RelativeLayout
- android:id="@+id/content_container"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- //Your content here
- </RelativeLayout>
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width
- android:layout_height="wrap_content"
- android:background="@color/color_primary"/>
- <RelativeLayout
- android:id="@+id/panel"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- //Your panel content here
- </RelativeLayout>
- </com.nikoyuwono.toolbarpanel.ToolbarPanelLayout>
關鍵在於設定panelId和toolbarId到ToolbarPanelLayout以便讓它決定在哪裡繪製面板
開啟喝關閉面板可以呼叫:
- ToolbarPanelLayout.openPanel();// Open the panel
- ToolbarPanelLayout.closePanel();// Close the panel
鎖定面板你可以使用ToolbarPanelLayout.setLockMode(int lockMode); 它支援3種模式:
- /**
- * The drawer is unlocked.
- */
- publicstaticfinalint LOCK_MODE_UNLOCKED =0;
- /**
- * The drawer is locked closed. The user may not open it, though the app may open it
- * programmatically.
- */
- publicstaticfinalint LOCK_MODE_LOCKED_CLOSED =1;
- /**
- * The drawer is locked open. The user may not close it, though the app may close it
- * programmatically.
- */
- publicstaticfinalint LOCK_MODE_LOCKED_OPEN =2;
你還可以為ToolbarPanelLayout設定ToolbarPanelListener,目前支援3種事件:
- /**
- * Called when a panel's position changes.
- */
- publicvoid onPanelSlide(Toolbar toolbar,View panelView,float slideOffset);
- /**
- * Called when a panel has settled in a completely open state.
- * The panel is interactive at this point.
- */
- publicvoid onPanelOpened(Toolbar toolbar,View panelView);
- /**
- * Called when a panel has settled in a completely closed state.
- */
- publicvoid onPanelClosed(Toolbar toolbar,View panelView);
下載
你可以通過Gradle來獲得:
- compile 'com.nikoyuwono:toolbar-panel:0.1'