I want to place a search into my apps Toolbar. So the user has the default Toolbar with a search action icon. When clicking it, the Toolbar should resize and get bigger or a bigger alternative slides in from above. It should show some search field and other controls in it. By exiting the search the Toolbar should resize back to default or slide out.
Google Maps uses something similar (not exactly, maybe it's not a Toolbar at all but it looks like) when you press the blue floating action button:
Is there a best practice for this? How to do this?
The Toolbar is basically the advanced successor of the ActionBar. It is much more flexible and customizable in terms of appearance and functionality. Unlike ActionBar, its position is not hardcoded i.e., not at the top of an activity.
Make a menu xml This is going to be in res/menu/main_menu . Right click the res folder and choose New > Android Resource File. Type main_menu for the File name. Choose Menu for the Resource type.
Make a custom toolbar and add buttons,images,textview in it and than add it to your Activities
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="150dp"
android:layout_width="match_parent"
android:background="@color/ColorPrimary"
android:elevation="0dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
xmlns:android="http://schemas.android.com/apk/res/android" >
</android.support.v7.widget.Toolbar>
and inside your activity
Toolbar mToolbar = (Toolbar) findViewById(R.id.tool_bar);
this.setSupportActionBar(mToolbar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With