Android Bottom Navigation Menu with 4 items - android

I am trying to get 4 items on my bottom menu, but the 4th one isn't animating, should I switch to an entirely different menu format, I thought that this menu type would support 3-5 items.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#mipmap/news_icon"
android:title="#string/title_news" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_dashboard_black_24dp"
android:title="#string/title_schedule" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/ic_notifications_black_24dp"
android:title="#string/title_team" />
<item
android:id="#+id/login"
android:icon="#drawable/ic_notifications_black_24dp"
android:title="#string/title_team" />
</menu>
Main Activity code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tibblist.attkapp.MainActivity">
<FrameLayout
android:id="#+id/content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="#menu/navigation" />
</LinearLayout>

I made a dumb mistake turns out I wasn't returning true for that switch statement in my onNavigationItemSelected function.

Related

Android- bottom Navigation bar is long

bottom Navigation bar is long seems like a space is excreted, i tried to solve this problem a days.
This is the problem
:
This is the xml code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
android:fitsSystemWindows="true"
tools:context=".Home_activity">
<!-- 813dp -->
<fragment
android:id="#+id/fragment"
android:name="com.anonymous.nr_chemistryteam.BlankFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.bottomappbar.BottomAppBar
android:id="#+id/bottomAppBar"
style="#style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="#color/white"
android:theme="#style/AppThemeMaterial2"
app:fabCradleMargin="8dp"
app:fabCradleRoundedCornerRadius="50dp"
app:fabCradleVerticalOffset="6dp">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/homeNvBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:background="#drawable/empty_background"
app:menu="#menu/bottom_menu" />
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#ff5e00"
android:src="#drawable/ic_cart"
app:fabCustomSize="72dp"
app:layout_anchor="#id/bottomAppBar"
app:maxImageSize="34dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
This is the menu xml code :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/home_page2"
android:icon="#drawable/ic_home2"
android:title="Home" />
<item
android:id="#+id/message_page2"
android:icon="#drawable/ic_message1"
android:title="Message" />
<item
android:id="#+id/placeholder"
android:checkable="false"
android:title="" />
<item
android:id="#+id/help_page2"
android:icon="#drawable/ic_help"
android:title="Help" />
<item
android:id="#+id/settings_page2"
android:icon="#drawable/ic_settings"
android:title="Settings" />
I am using coordinator layout so i think coordinator layout is the problem or might be the fragment i used.
what should i do to remove this space (space below bottom Navigation bar that already in picture)?
You could try making the height of the Bottom Bar 100dp.

BottomNavigationView dont show menu

I'm trying to add a BottomMenu to my app but it doesn't appear. I have tried changing the background color, adding the wight property but nothing works.
My activity
<androidx.constraintlayout.widget.ConstraintLayout
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">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="#dimen/_40sdp"
android:background="#fff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
bottommenu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/dateAndTimeFragment"
android:title="Home"
android:icon="#drawable/ic_baseline_home_24"
/>
<item
android:id="#+id/settingsFragment"
android:title="SMS"
android:icon="#drawable/ic_baseline_settings_24"
/>
<item
android:id="#+id/messagesFragment"
android:title="CONFIGURATION"
android:icon="#drawable/ic_baseline_settings_24"
/>
</menu>
Here you can see how it does not show anything

MaterialBottomNavigation has no animations

My Bottomnavigationbar has no animations when i tap items. I tried changing themes, colors etc. they still don't show up. I want the items to get bigger and show the titles. Normal bottomnavigationbar also has the same issue. Do i need to do this programmatically or is it supposed to animate the items when they are pressed?
BottomNavigation:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:id="#+id/mainFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/btnm"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/toolbar" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/btnm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="#+id/mainFragment"
app:menu="#menu/nav_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
Items:
<?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">
<item
android:id="#+id/settings"
android:title="Settings"
android:icon="#drawable/ic_settings_black_24dp" />
<item
android:id="#+id/pls"
android:icon="#drawable/ic_storage_black_24dp"
android:title="Plugins" />
<item
android:id="#+id/software"
android:icon="#drawable/ic_baseline_home_24"
android:title="Manage" />
<item
android:id="#+id/deletepls"
android:icon="#drawable/ic_delete_sweep_black_24dp"
android:title="Delete plugins" />
<item
android:id="#+id/consolepage"
android:icon="#drawable/ic_desktop_mac_black_24dp"
android:title="Console"/>
</menu>

adding a text over the item of bottomnavigationview

how to add a text over the item of bottomnavigationview?
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/lightGray"
android:layoutDirection="rtl"
app:itemIconTint="#drawable/nav_color_selecton"
app:itemTextAppearanceActive="#style/bottom_navigation_textappreance"
app:itemTextAppearanceInactive="#style/bottom_navigation_textappreance"
app:itemTextColor="#drawable/nav_color_selecton"
app:menu="#menu/bottom_nav_menu"
android:elevation="0dp"
/>
in menu I add tooltipText for an item. but it doesn't show anything.
<?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"
>
<item
android:id="#+id/nav2"
android:icon="#drawable/ic_filter_list_green_24dp"
android:title="nav2"
/>
<item
android:id="#+id/nav1"
android:icon="#drawable/ic_baseline_more_horiz_24"
android:title="more"
android:tooltipText="123"
/>
</menu>
I want to have something like this:
picture of it

How to change the view of Design Tab of menu layout file for Bottom Navigation Activity (tools:showIn)

I only want to see my design as bottom navigation view so I had tried the following on menu.xml file by setting tools:showIn="bottom_navigation_view" but it is not making any effect to my design view tab
Image of menu view which I don't want
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="bottom_navigation_view">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_home_black_24dp"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_dashboard"
android:icon="#drawable/ic_dashboard_black_24dp"
android:title="#string/title_dashboard" />
<item
android:id="#+id/navigation_notifications"
android:icon="#drawable/ic_notifications_black_24dp"
android:title="#string/title_notifications" />
</menu>
So please suggest me such a value of tools:showIn which can work.
Add this to your layout and replace value of menu.
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:theme="#style/AppTheme"
app:menu="#menu/navigation"
android:layout_gravity="start"
android:id="#+id/navigation"
/>
menu.xml folder should be created under res ⇒ menu folder.
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.bottomnavigation.MainActivity">
<FrameLayout
android:id="#+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:itemBackground="#color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/navigation" />
Try this
activity_layout.xml
<android.support.design.widget.BottomNavigationView
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/colorPrimary"
app:itemIconTint="#drawable/bottom_nav_colors"
app:itemTextColor="#drawable/bottom_nav_colors"
app:menu="#menu/bottom_navigation_items"/>
bottom_navigation_items.xml (menu)
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_home"
android:icon="#drawable/ic_home_blue_48dp"
android:title="Home" />
<item
android:id="#+id/action_menu"
android:icon="#drawable/ic_apps_black_24dp"
android:title="Menu"
/>
<item
android:id="#+id/action_msg"
android:icon="#drawable/ic_chat_black_24dp"
android:title="Message Inbox"
/>
</menu>

Categories

Resources