Minwal
Minwal

Reputation: 41

Bottom Navigation View does not show the icons or titles

I am making an application with three items in the bottom navigation bar. I tried implementing it. The code looks fine, there are no errors, it just won't show the icons or the labels. I looked at other similar questions but none of them have an answer that i am looking for.

I am using android studio 3.3

Here is my Bottom Navigation View:

<RelativeLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  xmlns:app="http://schemas.android.com/apk/res-auto">

  <android.support.design.widget.BottomNavigationView
     android:layout_width="match_parent"
     android:layout_height="56dp"
     android:layout_alignParentStart="true"
     android:layout_alignParentBottom="true"
     app:menu="@menu/nav_items" />

The nav_items file

<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_home" />
<item
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_search" />
<item
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_account" />
</menu>

Upvotes: 4

Views: 6261

Answers (3)

N Jedidiah
N Jedidiah

Reputation: 1783

Look for an attribute called 'label visibility' and turn it to true for the entire bottom navigation

Upvotes: 0

Tamir Abutbul
Tamir Abutbul

Reputation: 7651

Try to use this :

<android.support.design.widget.BottomNavigationView
 android:layout_width="match_parent"
 android:layout_height="56dp"
 android:layout_alignParentStart="true"
 android:layout_alignParentBottom="true"
 app:menu="@menu/nav_items" 
 app:labelVisibilityMode="labeled"/>

Upvotes: 7

B4eight
B4eight

Reputation: 92

If you go to Android Studio -> File -> New Project -> Bottom Navigation Activity, there is a working sample by Android Studio that does your requirements.

For your nav_items file, you can try including android ids like below:

<?xml version="1.0" encoding="utf-8"?>

<item
    android:id="@+id/nav0"
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_home" />

<item
    android:id="@+id/nav1"
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_search" />

<item
    android:id="@+id/nav2"
    android:icon="@drawable/outline_home_black_18dp"
    android:title="@string/nav_account" />

If you are using Activities for your 3 items, you can add the following switch statement in your Application java file:

BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
    = item -> {
        switch (item.getItemId()) {

            case R.id.nav0:
                Intent intent = new Intent(YourActivity.this, NextActivity.class);
                startActivity(intent);
                break;
            case R.id.nav1:
                Intent intent1 = new Intent(YourActivity.this, AnotherActivity.class);
                startActivity(intent1);
                break;
            case R.id.nav2:
                Intent intent2 = new Intent(YourActivity.this, AnotherNextActivity.class);
                startActivity(intent2);
                break;     
        }
        return false;
    };


@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
    // Add below 2 lines for BottomNavigationBar
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.nav_items);
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
}

Hope this is helpful.

Upvotes: 0

Related Questions