3

I am about to develop an Android Application. In my app, I need to put action bar at the bottom of the screen. I have never done it before. I am afraid to start it referencing on links I found because most of the links suggest to use custom layout like RelativeLayout and LinearLayout because an Action bar cannot be placed at the bottom.

But the problem is I will put infinite list using Recycler View. What I am worrying is if I use RelativeLayout or LinearLayout, if the list is too long, action bar may not be fixed at the bottom of the screen. So I tried to use custom snackbar.

But I feel it is not good idea, because snack bar is not to use like this. But most apps nowadays are using action bar at the bottom. What I want to know is what is the best way to use action bar at the bottom in my case. I have never done putting action bar at the bottom. What would you suggest?

halfer
  • 19,824
  • 17
  • 99
  • 186
Wai Yan Hein
  • 13,651
  • 35
  • 180
  • 372
  • Use a [Bottom Navigation Bar](https://stackoverflow.com/a/46251598/3681880) rather than an Action Bar. – Suragch Sep 16 '17 at 08:32

3 Answers3

7

Too old question, I wanted to add the latest answer to those who are in need to add bottomAppBar

Here is an XML code to add BottomAppBar

<android.support.design.widget.CoordinatorLayout
    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">

  <!-- Other components and views -->

  <com.google.android.material.bottomappbar.BottomAppBar
      android:id="@+id/bar"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="bottom"
      app:navigationIcon="@drawable/ic_menu_24"/>

  <com.google.android.material.floatingactionbutton.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:layout_anchor="@id/bar"/>

</android.support.design.widget.CoordinatorLayout>

How to use it class file

BottomAppBar bar = (BottomAppBar) findViewById(R.id.bar);

bar.setOnMenuItemClickListener(new OnMenuItemClickListener() {
    @Override
    public boolean onMenuItemClick(MenuItem item) {
        // Handle actions based on the menu item
        return true;
    }
});

Example pic

enter image description here

Suresh Maidaragi
  • 2,173
  • 18
  • 25
3

Use Support ToolBar. Add ToolBar manually in xml inside a layout and set the layout in bottom.

        <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Use NoActionBar Theme in style

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

Then setup Support Toolbar in Activity like this

    // Find the toolbar view inside the activity layout
    Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    // Sets the Toolbar to act as the ActionBar for this Activity window.
    // Make sure the toolbar exists in the activity and is not null
    setSupportActionBar(toolbar);

And override OnCreateOptionsMenu(Menu menu) in Activity

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_home, menu);
    return true;
}

Screenshot

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
0

create custom layout and android:layout_alignParentBottom="true" in your xml file. then in your list set android:layout_marginBottom="50dp" to consider the height of the custom layout is 50dp

Muklas
  • 557
  • 7
  • 11