3

why the toolbar is not showing at the bottom ?

private void initToolbars() {

    Toolbar toolbarTop = (Toolbar) findViewById(R.id.toolbar_top);
    setSupportActionBar(toolbarTop);

    Toolbar toolbarBottom = (Toolbar) findViewById(R.id.drawer_layout);
    toolbarBottom.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()){
                case R.id.action_settings:
                    // TODO
                    break;
                // TODO: Other cases
            }
            return true;
        }
    });
    toolbarBottom.inflateMenu(R.menu.menu_main);

}

this xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_top"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize" />

    <android.support.v7.widget.Toolbar
        android:id="@+id/drawer_layout"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:minHeight="?attr/actionBarSize" />



</RelativeLayout>

I am getting toolbar at top only

Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • check this answer http://stackoverflow.com/questions/27482012/how-to-show-action-items-at-the-bottom-using-toolbar – IntelliJ Amiya Oct 09 '15 at 05:30
  • 1
    I took the code from that link , the Layout_height there is wrap_content also. you suggest to change it to match parent ? – Moudiz Oct 09 '15 at 05:33

4 Answers4

2

When you already defined android:layout_alignParentBottom="true" then no need to add android:layout_gravity="bottom".

For more problem you can visit here .I hope it will help you .

How to show action items at the bottom using Toolbar

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • 1
    even if Removed android:layout_gravity="bottom" its still not showing and as i commented before I took the code from the link you have mentioned – Moudiz Oct 09 '15 at 05:37
  • @Lakhan (Y) Move ahead – IntelliJ Amiya Oct 09 '15 at 07:37
  • 1
    I didnt testi it yet but I want to make an grid view with adapter image. I am facing problem with something. ill post a question tonight hope you can solve it . have a nice day @Lakhan intellij – Moudiz Oct 09 '15 at 07:53
  • @Moudiz we will try our best level -Regards Amiya And Lakhan – IntelliJ Amiya Oct 09 '15 at 07:54
  • 1
    @IntelliJAmiya Lakkahn I dont know if you know Okhttp but can you help me in this code ? http://stackoverflow.com/questions/33089581/what-is-the-reasong-of-this-error-java-io-ioexception-content-length-and-stream – Moudiz Oct 12 '15 at 22:35
  • @Moudiz Sorry .No Knowledge about this .Thanks . Please add links when post your question – IntelliJ Amiya Oct 13 '15 at 11:24
  • @IntelliJAmiya what do you mean ? what links should i add – Moudiz Oct 13 '15 at 11:39
2

Try this way

<RelativeLayout ...>
    <!-- top toolbar -->
    <Toolbar
        android:id="@+id/top_toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:background="?attr/colorPrimary"
    >

        ...

    </Toolbar>

    <ImageView
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/top_toolbar"
        android:src="@drawable/week1"
    />

    <!-- bottom toolbar -->
    <Toolbar
        android:id="@+id/bottom_toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:layout_alignParentBottom="true">

    </Toolbar>

    <!-- scrollable pane -->
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/image"
        android:layout_above="@id/bottom_toolbar">

        ...

    </ScrollView>
</RelativeLayout>
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
2

Try the below, this is working for me

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<!--Begin Top Bar-->
<android.support.v7.widget.Toolbar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary" />
</LinearLayout>

<!--Bottom bar-->
<android.support.v7.widget.Toolbar
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:alignParentBottom="true"/></LinearLayout>
Ramz
  • 935
  • 2
  • 12
  • 29
2

May be problem is with tw toolbar.

Try to use below code :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_alignParentBottom="true"
    android:background="?attr/colorPrimary" />

Your MainActivity.java

public class MainActivityextends AppCompatActivity {

private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
}

@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;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

Hope it helps you.

KishuDroid
  • 5,411
  • 4
  • 30
  • 47
  • When i applied ur code i had thi error .. can you know why ...http://stackoverflow.com/questions/33045449/this-activity-already-has-an-action-bar-supplied-by-the-window-decor-do-not-req – Moudiz Oct 09 '15 at 20:00