2

By default, with fab in the center, all icons are aligned to the right, but I need to have 3 icons on one side and the other, like in the example below.

enter image description here

The screenshot shows a click on one of the buttons, such a ripple is in the bottom appbar (not in the bottom navigation), a toast also appears when clicked, this can only be with a non-fake menuitem, and not for example an imageButton.

It is important that each icon is a real menuitem (not an imageButton), a long press on the menuitem should display a toast over the icon (as you can see in the screenshot), which is very important. I would be extremely grateful for your help!

menu.xml

<?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
        app:showAsAction="always"
        android:id="@+id/menu_home"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_home"
        android:title="@string/title_home" />

    <item
        app:showAsAction="always"
        android:id="@+id/menu_tasks"
        android:icon="@drawable/ic_tasks"
        android:title="@string/title_tasks" />

    <item
        app:showAsAction="always"
        android:id="@+id/menu_habits"
        android:icon="@drawable/ic_timer"
        android:title="@string/title_pomo" />

    <item
        android:id="@+id/menu_timer"
        app:showAsAction="always"
        android:icon="@drawable/ic_habit"
        android:title="@string/title_habits" />
</menu>

Current result:

enter image description here

  • 1
    Does this answer your question? [Bottom app bar problem with placing icons](https://stackoverflow.com/questions/54767397/bottom-app-bar-problem-with-placing-icons) – javdromero Jul 25 '21 at 15:39
  • @javdromero, This solution uses an imagebutton, which is why I won't get a toast over the icon with a long press, like with menuitem – Денис Вережников Jul 25 '21 at 15:56
  • You can achieve a ripple effect and also a toast with long click on an image view, there are other post about that. – javdromero Jul 25 '21 at 16:40

1 Answers1

4

I did it! I inflated the left side of the menu in the ActionMenuView. enter image description here

In layout:

<com.google.android.material.bottomappbar.BottomAppBar
    android:id="@+id/bottomAppBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:contentInsetStart="0.0dip"
    android:contentInsetLeft="0dp"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    app:menu="@menu/bottom_nav_menu_right">

    <androidx.appcompat.widget.ActionMenuView
        android:id="@+id/additional_menu"
        android:layout_width="wrap_content"
        android:layout_height="?actionBarSize" />
</com.google.android.material.bottomappbar.BottomAppBar>

bottom_nav_menu_left:

<?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/menu_tasks"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_tasks"
        android:title="tasks"
        app:showAsAction="always" />

    <item
        android:id="@+id/menu_habit"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_habit"
        android:title="habits"
        app:showAsAction="always" />

    <item
        android:id="@+id/menu_add"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_add"
        android:title="add"
        app:showAsAction="always" />
</menu>

bottom_nav_menu_right:

<?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/menu_nav"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_menu"
        android:title="menu"
        app:showAsAction="always" />

    <item
        android:id="@+id/menu_home"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_home"
        android:title="home"
        app:showAsAction="always" />

    <item
        android:id="@+id/menu_timer"
        android:layout_alignParentRight="true"
        android:icon="@drawable/ic_timer"
        android:title="timer"
        app:showAsAction="always" />
</menu>

Inflating menu with left icons:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
        val actionMenuView = findViewById<ActionMenuView>(...)
        menuInflater.inflate(R.menu.bottom_nav_menu_left, actionMenuView.menu)
        ...
    }
}