0

How can i show the up arrow when i press the searchbutton in my actionbar? this is what i want enter image description here enter image description here this is in my activity's oncreate:

    getSupportActionBar().setDisplayShowTitleEnabled(false);
    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

this is in my styles.xml:

<style name="Theme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:icon">@drawable/ic_launcher</item>
    <item name="android:homeAsUpIndicator">@drawable/ic_launcher</item>
    <item name="homeAsUpIndicator">@drawable/ic_launcher</item>
</style>

this is in my menu.xml

<item android:id="@+id/searchGrid"
    android:title="@string/search_hint"
    android:icon="@drawable/ic_action_search"
    app:showAsAction="collapseActionView|ifRoom"
    app:actionViewClass="android.support.v7.widget.SearchView"/>

manifest file:

    <activity
        android:theme="@style/Theme"
        android:launchMode="singleTop"
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <meta-data android:name="android.app.searchable"
            android:resource="@xml/searchable" />

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEARCH" />
        </intent-filter>
    </activity>

OncreateOptionsMenu method:

    this.menu = menu;
    getMenuInflater().inflate(currentActionBar, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =(SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =(SearchView) menu.findItem(R.id.searchGrid).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    searchView.setInputType(InputType.TYPE_CLASS_NUMBER);

    return true;

Build.gradle dependencies:

    compile 'com.android.support:appcompat-v7:21.0.3'

Thank you so much if you guys could solve this for me, i've been searching for hours.

Emiel Vandenbussche
  • 363
  • 1
  • 5
  • 12
  • Indeed it should Show use more code (related to the menu item and the search) to help you debug. – shkschneider Jan 19 '15 at 15:38
  • 1
    if you are using AppCompat version 21,you cant get the result like this check out this guild line http://www.google.com/design/spec/layout/structure.html#structure-app-bar. but you can try this getSupportActionBar().setLogo(R.drawable.ic_launcher); – Ramz Jan 19 '15 at 16:05
  • thanx! So using a lower Appcompat version should solve the problem? Or is there a bether solution? This is wat my build.gradle looks like: compile 'com.android.support:appcompat-v7:21.0.3' – Emiel Vandenbussche Jan 19 '15 at 16:23
  • if you use the new version its difficult to get the result like this but its better to move on with the new version with lot of support and i have one thing to share check this http://stackoverflow.com/questions/26525229/toolbar-navigation-icon-never-set. – Ramz Jan 19 '15 at 16:38

1 Answers1

0

How about you set the app icon as background of your .xml file? Then you could add a button on top of the app icon to the left and attach different handlers depending on whether the search bar is opened or not. When searching is active, just set the text of the button to the '<' character.

Yeehaw
  • 105
  • 2
  • 11