1

I'm using BottomAppBar with image buttons. Following is the code for the bottomapbar.

<com.google.android.material.bottomappbar.BottomAppBar
            android:id="@+id/bar"
            style="@style/Widget.MaterialComponents.BottomAppBar"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/bottom_tab_height"
            android:layout_gravity="bottom"
            android:backgroundTint="@color/materialBlue"
            app:itemBackground="@color/colorPrimary"
            app:itemIconTint="@android:color/white"
            app:itemTextColor="@android:color/white"
            app:fabAlignmentMode="end"
            app:fabCradleRoundedCornerRadius="@dimen/activity_horizontal_margin3"
            app:hideOnScroll="true"
            >
            <include
                android:id="@+id/nav_bar"
                layout="@layout/bottom_navigation_bar" />
        </com.google.android.material.bottomappbar.BottomAppBar>

bottom_navigation_bar.xml

<?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"
    xmlns:tools="http://schemas.android.com/tools">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:paddingRight="16dp"
        android:weightSum="4"
       >

        <ImageButton
            android:id="@+id/home"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackgroundBorderless"
            app:srcCompat="@drawable/ic_home_black_24dp" />

        <ImageButton
            android:id="@+id/best_selling"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackgroundBorderless"
            app:srcCompat="@drawable/ic_add_shopping_cart_black_24dp" />


        <ImageButton
            android:id="@+id/settings_btn"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="?attr/selectableItemBackgroundBorderless"
            app:srcCompat="@drawable/ic_settings_black_24dp" />
    </LinearLayout>
</layout>

I'm having a hard time trying to highlight the selected ImageButtons. I tried to manually catch the select events and highlight them. But Is there a better way of doing the selected image button in the BottomAppBar?

  • It seems that you are trying to obtain a [NavigationView](https://github.com/material-components/material-components-android/blob/master/docs/components/BottomNavigationView.md) using a BottomAppBar – Gabriele Mariotti Sep 25 '19 at 11:22
  • Yes, because I want the fab to be floating as it is in BottomAppBar –  Sep 25 '19 at 11:30

0 Answers0