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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • initramfs学习「建议收藏」

    initramfs学习「建议收藏」(一)helloworld一、initramfs是什么在2.6版本的linux内核中,都包含一个压缩过的cpio格式的打包文件。当内核启动时,会从这个打包文件中导出文件到内核的rootfs文件系统,然后内核检查rootfs中是否包含有init文件,如果有则执行它,作为PID为1的第一个进程。这个init进程负责启动系统后续的工作,包括定位、挂载“真正的”根文件系统设备(如果有的话)。

    2022年8月11日
    13
  • 接口(Api)版本号命名规则

    接口(Api)版本号命名规则0.前言版本号的命名和更新问题,是开发者的责任感和前瞻性的问题。1.项目立项时版本格式:0.0.02.开发阶段时此时系统尚不稳定,随时可能增减或者修正API。版本格式:0.次版本号.修订号,版本号递增规则如下:主版本号:0表示正在开发阶段;次版本号:增加新的功能时增加;修订号:只要有改动就增加。3.开发完成后,发布API,或进入二方库时此时系统已经基本稳定…

    2025年10月23日
    3
  • static静态变量在内存中的存储[通俗易懂]

    static静态变量在内存中的存储[通俗易懂]static用来控制变量的存储方式和可见性    函数内部定义的变量,在程序执行到它的定义处时,编译器为它在栈上分配 空间,函数在栈上分配的空间在此函数执行结束时会释放掉,这样就产生了一个 问题:如果想将函数中此变量的值保存至下一次调用时,如何实现?最容易想 到的方法是定义一个全局的变量,但定义为一个全局变量有许多缺点,最明显的 缺点是破坏了此变量的访问范围(使得在此函数中定义的变量,不仅…

    2022年5月3日
    96
  • ‘builtin_function_or_method’ object is not subscriptable 错误

    ‘builtin_function_or_method’ object is not subscriptable 错误环境:Numpy问题:数组初始化报错错误❌:a=np.array[1,2,3,4,5,6,7,8,9,10]正确✅:a=np.array([1,2,3,4,5,6,7,8,9,10])这个问题一般是问题行内有圆括号缺失或者方括号的缺失。…

    2025年7月21日
    2
  • python和C语言的差别

    python和C语言的差别之前在公司一直做的是C语言的开发,然后做的都是业务方面的东西,做的是sdk,因为最近在找工作,然后今天面试的时候被问到C语言和Python的区别,自己只是简单的说了C是静态语言,在变量在使用前进行声明

    2022年7月5日
    29
  • Centos7.2安装Nginx实现负载平衡

    Centos7.2安装Nginx实现负载平衡

    2022年2月23日
    51

发表回复

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

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