Reputation: 7377
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
Upvotes: 3
Views: 977
Reputation: 5451
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.
Upvotes: 2
Reputation: 935
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>
Upvotes: 2
Reputation: 13555
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>
Upvotes: 2
Reputation: 75788
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 .
Upvotes: 2