Skip to content

Instantly share code, notes, and snippets.

@Velmm Velmm/MainActivity.java

Last active Dec 27, 2017
Embed
What would you like to do?
public class MainActivity extends AppCompatActivity {
private ActionBar toolbar;
private BottomNavigationView bottomNavigationView;
private String[] menus ={"Latest","Favorite","Cart","Profile"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = getSupportActionBar();
bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigationview);
bottomNavigationView.setOnNavigationItemSelectedListener(navigationItemSelectedListener);
toolbar.setTitle(menus[0]);
}
private BottomNavigationView.OnNavigationItemSelectedListener navigationItemSelectedListener = new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()){
case R.id.item1:
toolbar.setTitle(menus[0]);
return true;
case R.id.item2:
toolbar.setTitle(menus[1]);
return true;
case R.id.item3:
toolbar.setTitle(menus[2]);
return true;
case R.id.item4:
toolbar.setTitle(menus[3]);
return true;
}
return false;
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.