侧滑抽屉菜单 FlowingDrawer

导入依赖

        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);
            }
        });

    }

}

然后运行就可以运行了,布局就随便用图片和按钮代替了,具体布局和功能还得按需添加

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值