原文链接:
Bottom Navigation Views
Bottom navigation
提供了方便的导航在三到五个不同View之间进行切换。它是最近添加到
Material Design spec
,在
tabs
和
navigation drawers
之间提供了另一个选择。
design support library
配置说明添加依赖。尤其是确保更新到了v25版本,因为底部导航支持最近才被添加。
然后,在布局文件中添加
BottomNavigationView
并确保设置
alignParentBottom=true
来保证view放置在布局底部:
1 2 3 4 5 6
<android.support.design.widget.BottomNavigationView android:id ="@+id/bottom_navigation" android:layout_width ="match_parent" android:layout_height ="wrap_content" android:layout_alignParentBottom ="true" app:menu ="@menu/menu_bottom_navigation" />
然后,像配置Toolbar一样设置菜单资源,在
res/menu/menu_bottom_navigation.xml
文件中声明tabbed items和图标:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android ="http://schemas.android.com/apk/res/android" xmlns:app ="http://schemas.android.com/apk/res-auto" > <item android:id ="@+id/action_favorites" android:enabled ="true" android:icon ="@drawable/ic_favorite_white_24dp" android:title ="@string/text_favorites" app:showAsAction ="ifRoom" /> <item android:id ="@+id/action_schedules" android:enabled ="true" android:icon ="@drawable/ic_access_time_white_24dp" android:title ="@string/text_schedules" app:showAsAction ="ifRoom" /> <item android:id ="@+id/action_music" android:enabled ="true" android:icon ="@drawable/ic_audiotrack_white_24dp" android:title ="@string/text_music" app:showAsAction ="ifRoom" /> </menu >
你可以选择
New
->
Vector Asset
创建图标:
然后选择
Action
找到合适的图标:
保存文件为
ic_favorite_white_24dp.xml
。在导入vector drawable之后可以通过修改
fillColor
改变填充颜色:
1 2 3 4 5
<path android:fillColor ="#FFFFFFFF" android:pathData ="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z" /> </path >
你可以按照这个步骤处理其它图标。你也可以直接从
GitHub repo
下载。
最后,你需要设置导航选择的手动处理:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation); bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected (@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.action_favorites: return true ; case R.id.action_schedules: return true ; case R.id.action_music: return true ; } } });
https://medium.com/@hitherejoe/exploring-the-android-design-support-library-bottom-navigation-drawer-548de699e8e0
缺失模块。
1、请确保node版本大于6.2
2、在博客根目录(注意不是yilia根目录)执行以下命令:
npm i hexo-generator-json-content --save
3、在根目录_config.yml里添加配置:
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: false
tags: true