ibrahimsn98 / SmoothBottomBar

A lightweight Android material bottom navigation bar library
MIT License
1.94k stars 253 forks source link

Can I use it in java code ? #18

Open exzant opened 4 years ago

exzant commented 4 years ago

How ?

AbedQa commented 4 years ago

bottomBar.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelect(int i) { Log.d("",i + ""); } });

brookmg commented 4 years ago
smoothBottomBar.setOnItemSelectedListener(i -> {
    // i = the currently selected index
});

smoothBottomBar.setOnItemReselectedListener(i -> {
    // i = the currently reselected index
});

The above code can be used for setting the item selected and item reselected listeners. But to have this kind of simple expression you need to enable Java1.8 compile option.

go to your app.gradle file and add the following snippet inside the android object

android {
   ...

   compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }
}
sureshios commented 4 years ago

i need in java

1902shubh commented 3 years ago
private NavController navController;
private SmoothBottomBar bottomNavigationView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bottomNavigationView = findViewById(R.id.bottomBar);
    navController = Navigation.findNavController(this, R.id.nav_host_fragment);
    NavigationUI.setupActionBarWithNavController(this, navController);

    setupSmoothBottomBar();

}

private void setupSmoothBottomBar() {
    PopupMenu popupMenu = new PopupMenu(this, null);
    popupMenu.inflate(R.menu.bottom_nav);
    Menu menu  = popupMenu.getMenu();
    bottomNavigationView.setupWithNavController(menu, navController);
}

@Override
public boolean onSupportNavigateUp() {
    return navController.navigateUp() || super.onSupportNavigateUp();
}