导入依赖
implementation 'com.mxn.soul:flowingdrawer-core:2.0.0'
implementation 'com.nineoldandroids:library:2.4.0'
在styles.xml文件中 新建一个主题 目的为了去除标题栏, 防止侧滑菜单和标题栏冲突
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!--新建一个主题样式, 目的为了去掉标题栏-->
<style name="AppThemeNoTitle" parent="AppTheme" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
</resources>
然后在AndroidManifest.xml设置应用主题为 AppThemeNoTitle
使用方法 xml文件代码,
<?xml version="1.0" encoding="utf-8"?>
<com.mxn.soul.flowingdrawer_core.FlowingDrawer
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
app:edPosition="1"
app:edMenuSize="260dp"
app:edMenuBackground="#ffffff">
<!--content-->
<!--此处是页面的布局代码-->
<RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/img1"
/>
</RelativeLayout>
<!--menu-->
<com.mxn.soul.flowingdrawer_core.FlowingMenuLayout
android:id="@+id/menulayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--此处就是侧滑菜单的布局-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test1111"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="btn2"
/>
</LinearLayout>
</com.mxn.soul.flowingdrawer_core.FlowingMenuLayout>
</com.mxn.soul.flowingdrawer_core.FlowingDrawer>
Java代码
public class MainActivity extends AppCompatActivity {
private FlowingDrawer drawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//这句代码为使按钮点击事件生效
ButterKnife.bind(this);
drawer = findViewById(R.id.drawerlayout);
drawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
drawer.setOnDrawerStateChangeListener(new ElasticDrawer.OnDrawerStateChangeListener() {
@Override
public void onDrawerStateChange(int oldState, int newState) {
if (newState == ElasticDrawer.STATE_CLOSED) {
Log.i("MainActivity", "Drawer STATE_CLOSED");
}
}
@Override
public void onDrawerSlide(float openRatio, int offsetPixels) {
Log.i("MainActivity", "openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
}
});
}
}
然后运行就可以运行了,布局就随便用图片和按钮代替了,具体布局和功能还得按需添加