Android Material Bottom Navigation使用教程
2016-04-30 20:07
561 查看
今年三月Google已经将Bottom Navigation加入到Material中,但是目前还没有这方面的使用教程,所以本文介绍使用LuseenBottomNavigation
1、Google Material Design地址:
https://www.google.com/design/spec/components/bottom-navigation.html#
2、在项目中引用,采用 Gradle方式:
compile 'com.github.armcha:LuseenBottomNavigation:1.7.0'
3、在布局文件中增加BottomNavigationView
<com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
4、添加BottomNavigation按钮,图标资源和选中按钮变换的颜色
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigation);
BottomNavigationItem bottomNavigationItem = new BottomNavigationItem
("Record", ContextCompat.getColor(this, R.color.firstColor), R.drawable.ic_mic_black_24dp);
BottomNavigationItem bottomNavigationItem1 = new BottomNavigationItem
("Like", ContextCompat.getColor(this, R.color.secondColor), R.drawable.ic_favorite_black_24dp);
bottomNavigationView.addTab(bottomNavigationItem);
bottomNavigationView.addTab(bottomNavigationItem1);
5、设置每个按钮的点击事件
bottomNavigationView.setOnBottomNavigationItemClickListener(new OnBottomNavigationItemClickListener() {
@Override
public void onNavigationItemClick(int index) {
Toast.makeText(MainActivity.this, "Item " +index +" clicked", Toast.LENGTH_SHORT).show();
}
});
6、结合ViewPager使用
ContextCompat.getColor(context, R.color.firstColor)
bottomNavigationView.setUpWithViewPager(yourPager , colorResources , imageResources);
bottomNavigationView.disableViewPagerSlide();
7、自定属性
<com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:bnv_colored_background="true"
app:bnv_with_text="false"
app:bnv_shadow="true"
app:bnv_tablet="false"
app:bnv_viewpager_slide="true"
app:bnv_active_color="@color/colorPrimary"
app:bnv_active_text_size="@dimen/bottom_navigation_text_size_active"
app:bnv_inactive_text_size="@dimen/bottom_navigation_text_size_inactive"/>
8、设置始终显示文字和背景颜色不变
bottomNavigationView.isWithText(true);
bottomNavigationView.isColoredBackground(false);
bottomNavigationView.setItemActiveColorWithoutColoredBackground(yourColor);
9、demo运行截图:
10、源码下载
csdn
1、Google Material Design地址:
https://www.google.com/design/spec/components/bottom-navigation.html#
2、在项目中引用,采用 Gradle方式:
compile 'com.github.armcha:LuseenBottomNavigation:1.7.0'
3、在布局文件中增加BottomNavigationView
<com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
4、添加BottomNavigation按钮,图标资源和选中按钮变换的颜色
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottomNavigation);
BottomNavigationItem bottomNavigationItem = new BottomNavigationItem
("Record", ContextCompat.getColor(this, R.color.firstColor), R.drawable.ic_mic_black_24dp);
BottomNavigationItem bottomNavigationItem1 = new BottomNavigationItem
("Like", ContextCompat.getColor(this, R.color.secondColor), R.drawable.ic_favorite_black_24dp);
bottomNavigationView.addTab(bottomNavigationItem);
bottomNavigationView.addTab(bottomNavigationItem1);
5、设置每个按钮的点击事件
bottomNavigationView.setOnBottomNavigationItemClickListener(new OnBottomNavigationItemClickListener() {
@Override
public void onNavigationItemClick(int index) {
Toast.makeText(MainActivity.this, "Item " +index +" clicked", Toast.LENGTH_SHORT).show();
}
});
6、结合ViewPager使用
ContextCompat.getColor(context, R.color.firstColor)
bottomNavigationView.setUpWithViewPager(yourPager , colorResources , imageResources);
bottomNavigationView.disableViewPagerSlide();
7、自定属性
<com.luseen.luseenbottomnavigation.BottomNavigation.BottomNavigationView
android:id="@+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:bnv_colored_background="true"
app:bnv_with_text="false"
app:bnv_shadow="true"
app:bnv_tablet="false"
app:bnv_viewpager_slide="true"
app:bnv_active_color="@color/colorPrimary"
app:bnv_active_text_size="@dimen/bottom_navigation_text_size_active"
app:bnv_inactive_text_size="@dimen/bottom_navigation_text_size_inactive"/>
8、设置始终显示文字和背景颜色不变
bottomNavigationView.isWithText(true);
bottomNavigationView.isColoredBackground(false);
bottomNavigationView.setItemActiveColorWithoutColoredBackground(yourColor);
9、demo运行截图:
10、源码下载
csdn
相关文章推荐
- android 通知栏 notification
- android自定义适配屏幕的ImageView
- -Android -线程池 批量上传图片 -附php接收代码
- 【Android 基础】自定义ImageView
- Android ImageView图片自适应
- Android动画(一):帧动画+补间动画(代码创建)
- 学习笔记(十)运用通知和手机多媒体
- Android——按钮类控件
- android 5.x—Elevation阴影
- [android] WebView与Js交互
- Android小菜鸟向大神进攻的奋斗记(一)之关于Android studio 使用极光推送,集成成功,但是推送不成
- 实现带子菜单的选项菜单(学习笔记)
- 十一、观察者设计模式
- Android模仿IOS的自定义switch
- android,如果某个文件存在就删除
- Android RadioButton用代码去圆点失效的问题解决
- android关于时间的demo
- Android5.0之CardView的使用
- Android5.0之CardView的使用
- Android5.0之CardView的使用