1.github地址
https://github.com/Ashok-Varma/BottomNavigation
2.Gradle导入
compile 'com.ashokvarma.android:bottom-navigation-bar:1.4.1'
3.使用
1.xml布局文件
<com.ashokvarma.bottomnavigation.BottomNavigationBar
android:id="@+id/bottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:bnbMode="mode_fixed"
app:bnbActiveColor="#262626"
app:bnbInactiveColor="#888888" />
2.dimens.xml中
<resources>
<!-- BottomNavigation配置 -->
<dimen name="fixed_height">56dp</dimen> <!-- 高度 -->
<dimen name="fixed_icon_grid">24dp</dimen> <!-- icon大小 -->
<dimen name="fixed_height_top_padding_inactive">3dp</dimen> <!-- 未选中时顶部padding -->
<dimen name="fixed_height_top_padding_active">3dp</dimen> <!-- 选中时顶部padding -->
<dimen name="fixed_height_bottom_padding">5dp</dimen> <!-- 底部padding -->
<dimen name="fixed_label_active">12sp</dimen> <!-- 选中字体大小 -->
<dimen name="fixed_label_inactive">12sp</dimen> <!-- 未选中字体大小 -->
<item name="fixed_label_active_to_inactive_ratio" format="float" type="dimen">1</item> <!-- 默认文字大小缩放比率 -->
</resources>
3.java代码
bottomBar = (BottomNavigationBar) findViewById(R.id.bottomBar);
bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_home_selected_24dp,"首页")
.setInactiveIconResource(R.drawable.ic_home_unselected_24dp));
bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite_selected_24dp,"收藏")
.setInactiveIconResource(R.drawable.ic_favorite_unselected_24dp));
bottomBar.addItem(new BottomNavigationItem(R.drawable.ic_material_selected_24dp,"资料")
.setInactiveIconResource(R.drawable.ic_material_unselected_24dp));
bottomBar.initialise();
网友评论