build.gradle
implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.4'implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.70'
MENU
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"><itemandroid:id="@+id/home"android:title="Home"android:icon="@drawable/ic_home"app:cnb_backgroundColor="#ff785b"app:cnb_iconColor="#fff"app:cnb_textColor="#fff"/><itemandroid:id="@+id/score"android:title="Score"android:icon="@drawable/ic_home"app:cnb_backgroundColor="#ff785b"app:cnb_iconColor="#fff"app:cnb_textColor="#fff"/><itemandroid:id="@+id/Team"android:title="Team"android:icon="@drawable/ic_home"app:cnb_backgroundColor="#ff785b"app:cnb_iconColor="#fff"app:cnb_textColor="#fff"/></menu>
activity_main.xml
<?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=".MainActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.ismaeldivita.chipnavigation.ChipNavigationBar
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="68dp"
android:layout_alignParentBottom="true"
android:background="@drawable/rounded"
android:elevation="16dp"
android:padding="8dp"
app:cnb_menuResource="@menu/menu_bottom"/>
</RelativeLayout>
MainActivity.java
package com.anni.tpltajpur;import androidx.appcompat.app.AppCompatActivity;import androidx.fragment.app.Fragment;import androidx.fragment.app.FragmentManager;import android.os.Bundle;import android.util.Log;import com.google.android.material.tabs.TabLayout;import com.ismaeldivita.chipnavigation.ChipNavigationBar;public class MainActivity extends AppCompatActivity {ChipNavigationBar bottomNav;FragmentManager fragmentManager;private static final String TAG = MainActivity.class.getCanonicalName();@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bottomNav = findViewById(R.id.bottom_nav);if (savedInstanceState==null) {bottomNav.setItemSelected(R.id.home, true);fragmentManager = getSupportFragmentManager();HomeFragment homeFragment = new HomeFragment();fragmentManager.beginTransaction().replace(R.id.fragment_container, homeFragment).commit();}bottomNav.setOnItemSelectedListener(new ChipNavigationBar.OnItemSelectedListener() {@Overridepublic void onItemSelected(int id) {Fragment fragment = null;switch (id){case R.id.home:fragment= new HomeFragment();break;case R.id.score:fragment= new ScoreFragment();break;case R.id.Team:fragment= new TeamFragment();break;}if (fragment!=null){fragmentManager = getSupportFragmentManager();fragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).commit();}else {Log.e(TAG, "Error in creating fragment");}}});}}
0 Comments