-
Notifications
You must be signed in to change notification settings - Fork 38
How to use Toolbar at the bottom of activity.
Rohit Singh edited this page Mar 1, 2018
·
2 revisions
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<item
android:id="@+id/add"
android:title="Add"
app:showAsAction="always"
/>
<item
android:id="@+id/filter"
android:title="filter"
app:showAsAction="always"
/>
<item
android:id="@+id/sort"
android:title="Sort"
app:showAsAction="always"
/>
</menu>
Inflate the menu and Add touch listener on MenuItem
ToolBar bottomToolBar = (Toolbar)findViewById(R.id.bottomToolbar);
bottomToolBar.inflateMenu(R.menu.bottom_menu);
bottomToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if(item.getItemId()==R.id.add)
{
Toast.makeText(MainActivity.this, "Add", Toast.LENGTH_SHORT).show();
}
else if(item.getItemId()== R.id.filter)
{
Toast.makeText(MainActivity.this, "Filter", Toast.LENGTH_SHORT).show();
}
else if(item.getItemId() == R.id.sort)
{
Toast.makeText(MainActivity.this, "Sort", Toast.LENGTH_SHORT).show();
}
return false;
}
});