DrawerLayout侧滑栏

DrawerLayout侧滑栏1.DrawerLayout是一个侧滑的布局控件2.以及可以拖拽的一个布局资源3.首先要现在布局文件里面设置好布局,在进行编写代码;第一步:这是最基本的一个布局文件,里面有主界面布局,下面是包含一个button的按钮;<android.support.v4.widget.DrawerLayoutxmlns:android="http://schemas.android.c…

大家好,又见面了,我是你们的朋友全栈君。

1.DrawerLayout是一个侧滑的布局控件

2.以及可以拖拽的一个布局资源

3.首先要现在布局文件里面设置好布局,在进行编写代码;

第一步:这是最基本的一个布局文件,里面有主界面布局,下面是包含一个button的按钮;

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="10dp">

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"></android.support.v4.view.ViewPager>

        <RadioGroup
            android:id="@+id/group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/radio1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:text="影片" />

            <RadioButton
                android:id="@+id/radio2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:text="影院" />
        </RadioGroup>
    </LinearLayout>

    <LinearLayout
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#fff"
        android:orientation="vertical"
        android:padding="10dp">
        <Button
            android:id="@+id/b6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="设置"
            android:textSize="20sp" />
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

第二步:设置ActionBar,以及侧滑栏的点击事件;

//========================设置ActionBar==================================================
private void initActionBar() {
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    toggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.open, R.string.close);
    toggle.syncState();
    drawerLayout.addDrawerListener(toggle);
}
//==================设置侧滑点击事件==================================================

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (toggle.onOptionsItemSelected(item)) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/148997.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月25日 下午9:36
下一篇 2022年6月25日 下午9:36


相关推荐

  • pycharm每次打开都更新_pycharm运行配置错误

    pycharm每次打开都更新_pycharm运行配置错误pycharm更新之后显示问题在新版pycharm中等号和其他符号会连在一块,下面是解决方法添加公众号:

    2022年8月28日
    10
  • __cplusplus介绍

    __cplusplus介绍伪代码如下 ifdef cplusplusext C endif include lt h gt ifdef cplusplus endif 如果在 C 的编译环境中 代码就变成了 include lt h gt 如果在 C 环境中 代码就变成了 extern C include lt h gt 这个 cplusplus 在编译器中被定义 不同的 C 版本有不同的值 C 03 cplusplus

    2026年3月16日
    1
  • 两个div并排,左边div固定宽度,右边宽度自适应

    两个div并排,左边div固定宽度,右边宽度自适应

    2021年11月22日
    46
  • 智慧小区解决方案ppt_智慧小区简介

    智慧小区解决方案ppt_智慧小区简介智慧小区项目遇到的问题汇总&解决参考跨域问题mybatisplus操作问题git操作问题跨域问题前端使用vue脚手架搭建项目,后端使用springboot+MySQL,首当其冲的问题是两者不能使用同一个端口启动,这就涉及到跨域操作。事实上,第一步,要在vue项目中的vue.config.js里添加//跨域parallel:require(‘os’).cpus().length>1,pwa:{},devServer:{port:8081,

    2022年10月17日
    5
  • vue-router传递参数的几种方式

    vue-router传递参数的几种方式vue-router传递参数分为两大类编程式的导航router.push声明式的导航&lt;router-link&gt;编程式的导航router.push编程式导航传递参数有两种类型:字符串、对象。字符串字符串的方式是直接将路由地址以字符串的方式来跳转,这种方式很简单但是不能传递参数:this.$router.push("home");对象想要传递参数主要就是以对象的方式来写,分为两种方…

    2022年7月11日
    31
  • php json字符串转json对象_PHP字符串函数

    php json字符串转json对象_PHP字符串函数怎么把php字符串转为json发布时间:2020-07-2214:05:08来源:亿速云阅读:162作者:Leah这期内容当中小编将会给大家带来有关怎么把php字符串转为json,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。php把字符串转为json的方法:首先定义一个数组,调用json_encode方法将数组编码为json格式的字符串;然后添加参数“true…

    2025年6月22日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号