Android底部导航栏

简介: Android底部导航栏 今天简单写了一个底部导航栏,封装了一个库,用法比较简单效果图 Github地址:https://github.

Android底部导航栏

今天简单写了一个底部导航栏,封装了一个库,用法比较简单

效果图

这里写图片描述

Github地址:https://github.com/kongqw/KqwBottomNavigation

导入库

P2

P3

XML布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.kongqw.bottomnavigationlib.KqwBottomNavigation
        android:id="@+id/kbn"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

使用

package com.kongqw.kqwbottomnavigation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.kongqw.bottomnavigationlib.KqwBottomNavigation;
import com.kongqw.bottomnavigationlib.OnBottomNavigationSelectedListener;
import com.kongqw.bottomnavigationlib.ToastUtil;

public class MainActivity extends AppCompatActivity implements OnBottomNavigationSelectedListener {

    private KqwBottomNavigation mKqwBottomNavigation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mKqwBottomNavigation = (KqwBottomNavigation) findViewById(R.id.kbn);

        mKqwBottomNavigation.setBottomNavigationSelectedListener(this);
    }

    @Override
    public void onValueSelected(int index) {
        ToastUtil.show(this, "index = " + index);
    }
}

API

  • 添加底部按钮点击的监听
public void setBottomNavigationSelectedListener(OnBottomNavigationSelectedListener l)

点击后的回调如下

@Override
public void onValueSelected(int index) {
    ToastUtil.show(this, "index = " + index);
}
  • 设置底部栏某个功能为选中状态
public void setBottomNavigationClick(int index)

我这里为了方便,只设定了0~3,依次代表底部四个按钮,可以使用枚举,只允许传入特定的值

相关文章
|
城市大脑 大数据 Java
云栖大会精华回顾,历届亮点大放送
一年一度的云栖大会又开始了,阿里云开发者社区和大家一样,期待着这场超级科技盛会。一转眼,云栖大会已经步入了第13年,那些精彩瞬间,我们一起回顾
云栖大会精华回顾,历届亮点大放送
|
Java Android开发
Android热修复升级探索——资源更新之新思路
Android资源更新之新思路:我们在资源修复方法上取得了突破性进展!新的资源修复方法不论是在使用便捷性、补丁包大小还是运行时效率方面,相比其他实现都有巨大的优势。
12172 1
|
2天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。
|
12天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
6天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
474 199
|
4天前
|
人工智能 移动开发 自然语言处理
2025最新HTML静态网页制作工具推荐:10款免费在线生成器小白也能5分钟上手
晓猛团队精选2025年10款真正免费、无需编程的在线HTML建站工具,涵盖AI生成、拖拽编辑、设计稿转代码等多种类型,均支持浏览器直接使用、快速出图与文件导出,特别适合零基础用户快速搭建个人网站、落地页或企业官网。
587 157