Android studio用户,在dependencies中添加资源
compile 'com.roughike:bottom-bar:1.3.4'
一 在菜单资源文件中新建 底部菜单文件
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/bottomBarItemOne" android:icon="@drawable/ic_recents" android:title="Recents" /> ... </menu>
icon为所显示的图标,title为所显示的名称
二 接着在Activity中 实例化Bottombar
public class MainActivity extends AppCompatActivity { private BottomBar mBottomBar; //BottomBar对象 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);//实例化BottomBar对象 mBottomBar = BottomBar.attach(this, savedInstanceState);//R.menu.bottombar_menu所显示的菜单资源文件 mBottomBar.setItemsFromMenu(R.menu.bottombar_menu, new OnMenuTabClickListener() { @Override public void onMenuTabSelected(@IdRes int menuItemId) { if (menuItemId == R.id.bottomBarItemOne) { // 添加点击事件 } } @Override public void onMenuTabReSelected(@IdRes int menuItemId) { if (menuItemId == R.id.bottomBarItemOne) { // The user reselected item number one, scroll your content to top. } } }); // Setting colors for different tabs when there's more than three of them. // You can set colors for tabs in three different ways as shown below//点击时变化的颜色
mBottomBar.mapColorForTab(0, ContextCompat.getColor(this, R.color.colorAccent)); mBottomBar.mapColorForTab(1, 0xFF5D4037); mBottomBar.mapColorForTab(2, "#7B1FA2"); mBottomBar.mapColorForTab(3, "#FF5252"); mBottomBar.mapColorForTab(4, "#FF9800"); }