I am trying to implement a simple bottom navigation bar on my android app using the Material Design library. I looked at tutorials and several other sites and Medium articles, and the code seems pretty simple/boilerplate; however, the icons in my bottom navigation bar do not seem to exist (given that setting (layout_height = wrap_content makes the entire bar shrink to nothing).
I am not sure why the bottom nav bar appears to be empty or not show anything.
activity_main.xml:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="400dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="#layout/layout" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav"
app:labelVisibilityMode="labeled"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
bottom_nav.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/nav_rest"
android:icon="#drawable/ic_rest_nav"
android:enabled="true"
android:title="Restaurant-List"
/>
<item
android:id="#+id/nav_maps"
android:icon="#drawable/ic_location_24dp"
android:enabled="true"
android:title="Map"
/>
<item
android:id="#+id/nav_menu"
android:icon="#drawable/ic_menu_24dp"
android:title="Menu"
/>
<item
android:id="#+id/nav_cart"
android:icon="#drawable/ic_cart_24dp"
android:title="nav_cart"
/>
</menu>
in your activity_main.xml :RecyclerView
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="400dp"
should be
app:layout_constraintBottom_toTopOf="#id/bottom_nav_bar"
android:layout_width="0dp"
Related
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
I am using a bottom Navigation View with menus. I need to place the menu icons in the center of the BNV as I don't want to place text with the icons.
Here is my bottom Navigation View:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment_dashboard"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/dashboard_navigation" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_nav_menu"
app:labelVisibilityMode="labeled"
android:background="#color/white"
app:elevation="12dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
And here is the menu code
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/homeFragment"
android:title=""
android:icon="#drawable/home_icon"/>
<item
android:id="#+id/chatFragment"
android:title=""
android:icon="#drawable/chat_icon"
/>
<item
android:id="#+id/nonSulinCommunityFragment"
android:title=""
android:icon="#drawable/nonsulin_community_icon"
/>
<item
android:id="#+id/notificationsFragment"
android:title=""
android:icon="#drawable/notification_icon"
/>
<item
android:id="#+id/profileFragment"
android:title=""
android:icon="#drawable/profile_icon"
/>
</menu>
Here is the ss of the bottom nav and I need to place icons in the center of the bottom Nav Menu.
Get rid of the android:title="" in the xml file and it should work
So I resolved the issue by changing
app:labelVisibilityMode="labeled"
to
app:labelVisibilityMode="unlabeled"
as I was not using any title with the menu.
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>
I want to do something like this in my android app.
I tryied with app bar and fab button but was unsuccessful.
Do you have any ideas?
I have created a Bottom navigationView with 5 menu items.
The middle item has no image.
So I added an imageButton(android:clickable="false") inside the bottom navigationView.
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav_instructor"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
android:background="#color/bg_bottom_nav_bar"
android:elevation="15dp"
app:itemIconSize="30dp"
app:itemIconTint="#drawable/bottom_navigation_colors"
app:itemTextAppearanceActive="#style/TextStyleTab"
app:itemTextAppearanceInactive="#style/TextStyleTab"
app:labelVisibilityMode="labeled"
app:menu="#menu/instructor_bottom_nav">
<ImageButton
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_gravity="center"
android:layout_marginBottom="15dp"
android:background="#drawable/fab"
android:clickable="false"
android:src="#drawable/ico_add" />
</com.google.android.material.bottomnavigation.BottomNavigationView>
to acheive this you need a custom view. You can do this by creating a custom view class with extending BottomNavigationBar.
You can look at this article to try to acheive your desired look for your BottomNavigationBar.
Originally answered here: https://stackoverflow.com/a/70409454/8956093
I achieved same UI using Frame layout. Here is the code
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toTopOf="#id/bottom_navigation"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_graph_home" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_white_rounded_top"
app:itemTextColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/bottom_nav_bar_home_items"
app:labelVisibilityMode="unlabeled">
</com.google.android.material.bottomnavigation.BottomNavigationView>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<ImageView
android:id="#+id/toggle_alignment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_home_scan" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
and do not give icon for middle item.
<?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="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="#+id/firstFragment"
android:icon="#drawable/ic_one"
android:title="" />
<item
android:id="#+id/secondFragment"
android:icon="#drawable/ic_two"
android:title="" />
<item
android:id="#+id/thirdFragment"
android:title="" />
<item
android:id="#+id/fourthFragment"
android:icon="#drawable/ic_four"
android:title=""/>
<item
android:id="#+id/fifthFragment"
android:icon="#drawable/ic_five"
android:title="" />
</group>
</menu>
I want imitate the menu as saw in picture.
Tried by using compile 'com.github.armcha:SpaceNavigationView:1.6.0' but is old and don't wanna change all entire code of my default activity with bottom navigation view.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<include
layout="#layout/content_main"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<!-- app:layout_constraintTop_toBottomOf="#+id/appBarLayout"-->
<android.support.design.widget.BottomNavigationView
android:id="#+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:background="#drawable/rett_arr_blu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="#menu/bottom_nav_menu"
app:labelVisibilityMode="unlabeled"
/>
</android.support.constraint.ConstraintLayout>
bottom_nav_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_home"
android:icon="#drawable/ic_home_black_24dp"
android:iconTint="#android:color/white"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_news"
android:icon="#drawable/ic_notifications_black_24dp"
android:title="#string/title_news" />
<item
android:id="#+id/navigation_mappa"
android:icon="#drawable/ic_map_black_24dp"
android:title="#string/title_mappa" />
<item
android:id="#+id/navigation_convenzioni"
android:icon="#drawable/ic_convention"
android:title="#string/title_convenzioni" />
<item
android:id="#+id/navigation_altro"
android:icon="#drawable/ic_altro"
android:iconTint="#android:color/white"
android:title="#string/title_altro" />
</menu>
Result must be as picture in this repository: armcha/Space-Navigation-View. Search by google and find it...