使用Android support library25.0.0 提供的BottomNavigationView实现底部导航功能

news/2024/7/4 10:10:13

为什么80%的码农都做不了架构师?>>>   hot3.png

底部导航控件,我们一般使用的是tab页的形式,或各种自定义的样式(tablayout,radiogroup等),最近android25 support库中提供了BottomNavigationView,使得我们能实现更加炫酷的效果,当然,这个效果很多大牛早已实现了,可参考: 1.https://github.com/roughike/BottomBar

输入图片说明

2.https://github.com/aurelhubert/ahbottomnavigation

输入图片说明

上面的效果显然更加炫酷,但google官方出了相应控件,还是要优先使用的。 使用步骤如下:

  1. 导入库
compile 'com.android.support:design:25.0.0'
  1. 新建底部导航使用到的菜单文件:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/add"
        android:icon="@android:drawable/ic_menu_call"
        android:title="call" />
    <item
        android:id="@+id/delete"
        android:icon="@android:drawable/ic_menu_camera"
        android:title="message" />
    <item
        android:id="@+id/setting"
        android:icon="@android:drawable/ic_menu_compass"
        android:title="setting" />

    <item
        android:id="@+id/me"
        android:icon="@android:drawable/ic_menu_gallery"
        android:title="me"/>
</menu>
  1. 布局中引入控件:
<android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        app:menu="@menu/navigation"/>

4.代码处理:

mNavigationView = (BottomNavigationView) findViewById(R.id.navigation);

        mNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        mTextView.setText(item.getTitle().toString().toUpperCase());
                        return true;
                    }
                });

至此,可观察效果如下:

输入图片说明

使用google官方的tablayout控件实现底部导航效果,可参考我的另一个博文: 使用android support library中的tablayout实现页签切换效果出现的问题

转载于:https://my.oschina.net/Gxhpro/blog/774745


http://www.niftyadmin.cn/n/4115463.html

相关文章

动手学数据分析task05 数据建模及模型评估

特征工程 缺失值的填充 分类型变量 填充某个缺失值字符(NA)用最多类别的进行填充 连续型变量 填充均值、中位数、众数 第一步&#xff1a;查看所有属性列中有哪些有缺失值 train.isnull().sum().sort_values(ascendingFalse)第二步&#xff1a;查看某一个属性列有多少种取…

Ubuntu14.04安装pycharm并配置pycharm运行Django工程

1、安装jdk1.8 sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer2、设置环境变量输入vim ~/.bashrc&#xff0c;在文件末尾添加 export JAVA_HOME/usr/lib/jvm/java-8-oracle export JRE_HOME${JAVA_HOME}/jre…

np.meshgrid函数解读

numpy.meshgrid()——生成网格点坐标矩阵 以生成6个点的网格图为例 若是有大量的格点 可以看出&#xff0c;上面这种很繁琐&#xff0c;如果改为meshgrid函数则稍微简单一些&#xff08;因为他们的x,y坐标都很有规律&#xff09;

C语言指针(个人的认识)

有人说指针是C语言的灵魂&#xff0c;可见指针的重要性。 下面我们就开门见山。 一、指针定义 指针即地址&#xff0c;指针变量是存储指针的变量。 二、指针的声明 int * p&#xff0c;&#xff08;表示p变量存储一个int类型变量的地址。&#xff09; #include<stdio.h>v…

nilmtk介绍_user版本

安装nilmtk data the load api load data into memory Meter selection and basic statistics New: The experimentation API: check also NILMTK-contrib for some related material and related paper. nilmtk -contrib https://github.com/nilmtk/nilmtk-contrib Legacy: …

pybrain安装及测试

根据别人的博客进行执行https://blog.csdn.net/clheang/article/details/46455599 Linux和windows不一样&#xff0c;在Linux都需要使用terminal(注意有一个进入根目录的操作&#xff0c;不能直接python setup.py install ) pip install https://github.com/pybrain/pybrain/ar…

lua基金会【五岁以下儿童】I/O文件操作

--[[lua操作相关文件I/O ]]----件,假设该文件不存在的话&#xff0c; --lua会帮助我们在你规定的文件夹下创建这个文件&#xff0c;前提是该文件夹要存在 --[[ 同一时候我们应该掌握写入文件的模式&#xff1b;对下面写入模式进行说明&#xff1a; "r" 模式&#xff…

day2数学运算、字符串和文本、列表

注释的使用 单行注释用#&#xff0c;多行注释用’’’ ‘’’ 数学运算 字符串和文本 组合输出字符串的方法一&#xff1a;print()内部用逗号隔离开 组合输出字符串的方法二&#xff1a;一个’’’内部加入占位符输出想要信息 组合输出字符串的方法三&#xff1a;用format函数…