Skip to content

chenshixin/BottomNavigationInKotlin

Repository files navigation

BottomNavigationInKotlin

Bottom navigation widget written using Kotlin language

#Features

  • Basic bottom navigation features(icons, text, colors...)
  • Interface to judge if to open a tab
  • Fragment manage
  • Badge view supoorted
  • Double tap to scroll to top

#Installing In your root build.gradle, add maven { url "https://jitpack.io" }

allprojects {
 repositories {
    jcenter()
    maven { url "https://jitpack.io" }
 }
}

and in your own module:

dependencies {
    compile 'com.github.chenshixin:BottomNavigationInKotlin:0.1'
}

#Screenshots

#Example in Java

  List<BottomNavigationItem> tabItems = new ArrayList<>();
  tabItems.add(new BottomNavigationItem("Book", 0, R.drawable.ic_account_balance_wallet_black_24dp, R.drawable.ic_add_shopping_cart_black_24dp));
  tabItems.add(new BottomNavigationItem("Fav", 1, R.drawable.ic_add_shopping_cart_black_24dp, R.drawable.ic_alarm_black_24dp));
  tabItems.add(new BottomNavigationItem("White", 2, R.drawable.ic_alarm_black_24dp, R.drawable.ic_android_black_24dp));
  tabItems.add(new BottomNavigationItem("Link", 3, R.drawable.ic_android_black_24dp, R.drawable.ic_account_balance_wallet_black_24dp));
  tabItems.add(new BottomNavigationItem("Fav", 4, R.drawable.ic_add_shopping_cart_black_24dp, R.drawable.ic_alarm_black_24dp));

  final List<Fragment> fragments = new ArrayList<>();
  fragments.add(SimpleTextFragment.newInstance("Book"));
  fragments.add(SimpleTextFragment.newInstance("Fav"));
  fragments.add(SimpleTextFragment.newInstance("White"));
  fragments.add(SimpleTextFragment.newInstance("Link"));
  fragments.add(SimpleTextFragment.newInstance("Fav"));

  BottomNavigation bottomNavigation = (BottomNavigation) findViewById(R.id.bottom_navigation_bar_with_content);
  bottomNavigation.setTabItems(tabItems);
  bottomNavigation.setFragmentPagerAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
              @Override
              public Fragment getItem(int position) {
                  switch (position) {
                      case 0:
                          return SimpleTextFragment.newInstance("Explore");
                      case 1:
                          return SimpleTextFragment.newInstance("News");
                      default:
                          return SimpleTextFragment.newInstance("Mine");
                  }
              }

              @Override
              public int getCount() {
                  return 3;
              }
          });
  bottomNavigation.setTitleColorActive(Color.BLUE);
  bottomNavigation.setTitleColorInactive(Color.RED);
  bottomNavigation.setOnTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {
      @Override
      public boolean onTabWillBeSelected(int position) {
          if (position == 1) {
              Toast.makeText(MainActivity.this, "Need login first", Toast.LENGTH_SHORT).show();
          }
          return position != 1;
      }

      @Override
      public void onTabSelected(int position) {

      }

      @Override
      public void onTabUnselected(int position) {

      }

      @Override
      public void onTabReselected(int position) {

      }
  });
  bottomNavigation.initialise();
  bottomNavigation.setCurrentTab(0);

About

Bottom navigation widget written using Kotlin language

Resources

Stars

Watchers

Forks

Packages

No packages published