Android底部导航栏
16lz
2021-12-04
Android底部导航栏
今天简单写了一个底部导航栏,封装了一个库,用法比较简单
效果图
Github地址:https://github.com/kongqw/KqwBottomNavigation
导入库
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,依次代表底部四个按钮,可以使用枚举,只允许传入特定的值
更多相关文章
- 在Android(安卓)Studio 中导入opencv2.4.9
- Android之抽屉式弹窗功能
- Android给View画边框
- 导入android studio 项目错误:Error:(1, 0) Plugin with id 'com.
- android Select at least one project
- Android之TabHost重定义
- Android(安卓)大约Dialog弹出窗口
- Android(安卓)studio 导入github工程
- androidのActionbar