SlindingMenu侧滑简单新手小白加点击事件

Libs先在官方下载此模块进行依赖,下边是依赖方式

下边是布局,布局使用了DrawLayout加了一个ToolBarDraw可以换成LinerLayout



    xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:id="@+id/draw1"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

        android:layout_width="match_parent"

        android:layout_height="300dp"

        android:layout_gravity="left"

        android:background="#E11313">

        android:layout_width="match_parent"

        android:layout_height="200dp"

        android:layout_gravity="right"

        android:background="#0DF1AF">

    <!--  默认主页面  -->


        android:orientation="vertical"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        android:background="@mipmap/ic_launcher">

            android:background="@color/colorPrimary"

            android:id="@+id/toolbar"

            android:layout_width="match_parent"

            android:layout_height="60dp">

                android:id="@+id/tittle_tvtb"

                android:layout_gravity="center"

                android:text="标题是我"

                android:gravity="center"

                android:layout_width="wrap_content"

                android:layout_height="match_parent">

            android:layout_gravity="center"

            android:text="你好点击"

            android:id="@+id/btn1_slid"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content">

</androidx.drawerlayout.widget.DrawerLayout>




//SlindMenu的各种属性和使用方法

slidingMenu =new SlidingMenu(this);

//将当前页码作为你的主页面使用

slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

//支持的滑动模式

slidingMenu.setMode(SlidingMenu.LEFT_RIGHT);

//左侧菜单View res

slidingMenu.setMenu(R.layout.fragment_login);

View menuView =slidingMenu.getMenu();

menuView.findViewById(R.id.act_login_text).setOnClickListener(new View.OnClickListener() {

@Override

    public void onClick(View v) {

Toast.makeText(SlidingMenuAct.this, "您点击了你好", Toast.LENGTH_SHORT).show();

        tittleTvtb.setText("已经被点击过了哦");

    }

});

//右侧菜单

slidingMenu.setSecondaryMenu(R.layout.fragment_login);

View menuRightView =slidingMenu.getMenu();

//---------其他属性---------

//响应滑动位置

slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

//页面滑动出宽度

slidingMenu.setBehindWidth(SizeUtils.dp2px(300));

//侧滑页码进入遮照层透明度,起始值

slidingMenu.setFadeDegree(0);

//阴影

slidingMenu.setShadowDrawable(R.drawable.shadow);

slidingMenu.setShadowWidth(30);


slidingMenu.showMenu();



slidingMenu.showMenu();这个属性可以实现点击出现滑动菜单menu.toggle();这个属性可以动态判断当前menu是打开还是关闭打开则执行关闭,反之相同

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容