• 5
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

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>

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"/>
  • 1
Reply Report

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.

  • 0
Reply Report