7

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:

Google Maps Navigation

Is there a best practice for this? How to do this?

Michael
  • 2,528
  • 3
  • 21
  • 54

1 Answers1

2

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);
Muhammad Younas
  • 1,543
  • 1
  • 22
  • 32
  • Sounds good but how can I activate the new toolbar? What happens with the old and new option click handlers? – Michael Jan 07 '16 at 10:17
  • check my edits and you can set the click listener like we set in normal ways – Muhammad Younas Jan 07 '16 at 11:17
  • I already tried it. On setSupportActionBar I get an Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.support.v7.widget.Toolbar.getTitle()' on a null object reference – Michael Jan 07 '16 at 15:05
  • you want to set the title of the Toolbar ? you are gitting error on sitting the title of the tool bar – Muhammad Younas Jan 08 '16 at 11:57
  • No, your code: this.setSupportActionBar(mToolbar); <- there the exception is thrown – Michael Jan 08 '16 at 12:07
  • Found a way to switch the Toolbar here: http://stackoverflow.com/questions/3334048/android-layout-replacing-a-view-with-another-view-on-run-time This works but I try to optimize it some more. – Michael Jan 08 '16 at 14:23