Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Bottom navigation is a well-known feature in android applications. It is used in almost all applications, including Instagram, Facebook, Twitter, and more. Bottom navigation bars allow movement between primary destinations in an app.

In this article, we will dig into how we can implement a Bottom Navigation Bar in the Android app. Below is the preview of a sample Bottom Navigation Bar.

Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Navigation bar uses in android application:

  • Bottom navigation allows easy switching between different activities or fragments.
  • Users can easily identify that different screens are available.
  • Bottom navigation highlights the icon that the user is visiting.

Steps for Creating Bottom Navigation Bar

Step 1 - Create a new Android Studio project.

Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Step 2 - Adding the dependency to the build.Gradle(:app) file

Bottom navigation is available in the Material library. So, we need to import the material library, which we can do by adding the following dependency in our app-level build Gradle file.

implementation ‘com.google.android.material:material:1.1.0’

Step 3 - Designing Bottom Navigation

Go to the res folder and create a new Android Resouce Directory. Name the directory menu, select the resource type menu, and click on OK.

Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Now, go to the menu and create a menu resource file. Name file bottom_nav then click on OK.

After creating the bottom_nav.xml file. add a title, id, and icon as below:



    
    
    

Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Step 4 - Adding bottom navigation to MainActivity

We will add a relative layout to add different fragments (as you'll see in the next step) and bottom navigation where we give the app: menu id to our menu id.



    
    
    
    

`

After adding the following code, our navigation bar menu will look like this:

![](https://https://i0.wp.com/www.c-sharpcorner.com/article/bottom-navigation-bar-in-android/Images/img5.png)

Step 5 - Create a fragment to add to the bottom navigation.

After adding the Bottom Navigation Bar, we will want to perform an action by clicking the three bottom navigation bar buttons. Here we will create a fragment for each of the three navigation buttons to display the corresponding fragment upon clicking the navigation. Now that we have the three bottom navigation, we will create three fragments: dashboard, users, and profile. To create a Fragment, click on the app(right-click) -> New -> Fragment -> Fragment (Blank). Name the fragment Dashbord\_Fragment and the corresponding XML file fragment\_dashbord. To keep things simple, all three of the fragments should just contain a TextView. However, we can tweak this as we want it to be in the app. This is what the fragment\_dashbord.xml looks like after adding a TextView:
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".Fragment.DashbordFragment">

Like the above dashboard fragment, we will create users and profile fragments.

For a fine look create a directory named as av fragment and move all the fragments in that directory.

![](https://https://i0.wp.com/www.c-sharpcorner.com/article/bottom-navigation-bar-in-android/Images/img6.png)

Step 6 - Adding action to the Bottom Navigation 

Now we have set everything. Lastly, we must connect the navigation to our MainActivity and set the onNavigationItemSelectedListener.

First, we will implement our MainActvity to onNavigationItemSelectedListener and implements its methods like the below.
public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener

We will set the current fragment as the Dashboard Fragment using setCurrentFragment(). This takes a fragment as an argument and sets it in the FrameLayout of activity\_main.xml file. Now we will add the switch case in onNavigationItemSelectedListener to change the fragment upon clicking the navigation bar. After adding all these codes, the MainActivity looks like this:
import java.io.; import androidx.appcompat.app.AppCompatActivity; import androidx.annotation.NonNull; import com.example.Fragment.; import com.google.android.material.bottomnavigation.BottomNavigationView; import android.os.Bundle; import android.view.MenuItem; public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
BottomNavigationView bottomNavigationView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    bottomNavigationView = findViewById(R.id.bottonnav);
    bottomNavigationView.setOnNavigationItemSelectedListener(this);
    loadFragment(new DashbordFragment());
}
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment fragment = null;
    switch (item.getItemId()) {
        case R.id.dashbord:
            fragment = new DashbordFragment();
            break;
        case R.id.users:
            fragment = new usersFragment();
            break;
        case R.id.profile:
            fragment = new ProfileFragment();
            break;
    }
    if (fragment != null) {
        loadFragment(fragment);
    }
    return true;
}
void loadFragment(Fragment fragment) {
    //to attach fragment
    getSupportFragmentManager().beginTransaction().replace(R.id.relativelayout, fragment).commit();
}
} `

Output

Android bottom bar bb_bottom_bar_top_shadow.xml năm 2024

Conclusion

In this article, we have discussed what Bottom Navigation in android is and how it is used. All the steps are simple and contain all descriptions needed. Please comment for more details.

How do I fix the bottom navigation bar on my Android?

Steps for Creating Bottom Navigation Bar.

Step 1: Create a new Android Studio project. To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio..

Step 2: Adding the dependency to the build.gradle(:app) file. ... .

Step 3: Working with activity_main.xml file..

What is the default bottom bar on Android?

Represents a standard bottom navigation bar for application. It is an implementation of material design bottom navigation. Bottom navigation bars make it easy for users to explore and switch between top-level views in a single tap. They should be used when an application has three to five top-level destinations.

What is the bar at the bottom of the screen on my Android phone?

Together, the status bar and the navigation bar are called the system bars. They display important information such as battery level, the time, and notification alerts, and provide direct device interaction from anywhere.

How do I get rid of the bar at the bottom of my Android?

On the SureLock Settings screen, you will find the Disable Bottom Bar. Tap Disable Bottom Bar, which will disable all the shortcuts in the bottom bar of the device.