implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.2'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'
Add code in Main Activity:-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ChipBottomNavigation">
<FrameLayout
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="@+id/chip_bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/black"
android:elevation="@dimen/height_10"
app:cnb_menuResource="@menu/chip_bottom"
app:cnb_orientationMode="horizontal"
app:cnb_radius="@dimen/height_10"
app:cnb_unselectedColor="@color/white" />
</RelativeLayout>
Create chip_bottom in Menu file:-
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_baseline_storefront_24"
android:title="Home" />
<item
android:id="@+id/nav_whats"
android:icon="@drawable/whats_app"
android:title="WhataApp" />
<item
android:id="@+id/nav_trend"
android:icon="@drawable/facebook"
android:title="Facebook" />
<item
android:id="@+id/nav_twitter"
android:icon="@drawable/twitter"
android:title="Twitter" />
</menu>
Finally Add code in MainActivity.java/kotlin:-
ChipNavigationBar chipNavigationBar;
chipNavigationBar = findViewById(R.id.chip_bottom_nav);
chipNavigationBar.setItemEnabled(R.id.nav_home, true);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, new HomeFragment()).commit();
bottomMenu();
private void bottomMenu() {
chipNavigationBar.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() {
@Override
public void onItemSelected(int i) {
Fragment fragment = null;
switch (i) {
case R.id.nav_home:
fragment = new HomeFragment();
break;
case R.id.nav_whats:
fragment = new WhatsFragment();
break;
case R.id.nav_trend:
fragment = new FaceFragment();
break;
case R.id.nav_twitter:
fragment = new TwitFragment();
break;
}
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, fragment).commit();
}
});
}
Nice thanks for sharing 😊
ReplyDeleteGrate
ReplyDelete