Android底部导航栏

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

效果图

Android底部导航栏_第1张图片

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

导入库

Android底部导航栏_第2张图片

Android底部导航栏_第3张图片

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)

点击后的回调如下

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

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

更多相关文章

  1. 布局的学习
  2. 详解四种基本布局 (layout)
  3. Android 自定义View引用xml布局
  4. Android的AnimationSet动画实现图片的轮播,移动和切换可以自定义
  5. Android使用代码实现RelativeLayout,LinearLayout布局
  6. 在RelativeLayout布局中可以设置标签的android:layout_toLeftO..

随机推荐

  1. 联发科智能机战略转投Android(安卓)加速
  2. 学习android两年后有感
  3. Android图形系统的分析与移植--一、Andro
  4. Andy Rubin 说:「市场上」有约 600 万台 A
  5. Android内核和驱动篇-Android内核介绍
  6. 10个 iOS 用户暂可以嘲笑 Android(安卓)
  7. 联发科智能机战略转投Android(安卓)加速
  8. Windows电脑:Android(安卓)Studio 连接不
  9. Android内核和驱动篇-Android内核介绍
  10. 2021年Android开发实战!带你一起探究Andro