0

In my android app I am attempting to add a search icon to the action bar as well as add an icon since by default it is not appearing everything I am attempting has yet to work.

I am able to change the title of the AB but not add an icon

  getSupportActionBar().setIcon(R.drawable.ic_launcher);
    getSupportActionBar().setTitle("geekin radio");

When attempting to add the search box I use the following code

<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"
tools:context="com.geek.MainActivity">

<item android:id="@+id/search"
    android:title=""
    android:icon="@drawable/ic_action_action_search"
    android:showAsAction="always"
    android:actionViewClass="android.widget.SearchView" />

 </menu>

It still displays the three vertical dots that appear to be settings as opposed to showing my search icon. When I click on the icon it does display a search box though which I think is very odd.

Any ideas?

Will Jamieson
  • 918
  • 1
  • 16
  • 32
  • 2
    Half of your code (e.g., `getSupportActionBar()`) is attempting to use some action bar backport, probably `appcompat-v7`. Half of your code (e.g., `android:showAsAction`) appears to be attempting to use the native action bar. **Pick one and stick with it**. – CommonsWare Mar 03 '15 at 15:31
  • 3
    Use `app:showAsAction="always"`. Quoting docs This is necessary when using any XML attributes defined by the support library, because these attributes do not exist in the Android framework on older devices. So you must use your own namespace as a prefix for all attributes defined by the support library. http://developer.android.com/guide/topics/ui/actionbar.html – Raghunandan Mar 03 '15 at 15:31
  • Try this http://stackoverflow.com/a/26440473/1881611 – IshRoid Mar 03 '15 at 15:37
  • @Raghunandan Thanks that worked for me! had to add `app:actionViewClass` as well However I am still not getting the icon in the actionbar any ideas there? – Will Jamieson Mar 03 '15 at 15:45
  • @WillJamieson `app:actionViewClass="android.widget.SearchView" />` should work. But it has to be from the supprot library `app:actionViewClass="android.support.v7.widget.SearchView"` – Raghunandan Mar 03 '15 at 15:47
  • I plan to eventually add a naviagtion drawer as well. Would it make the most sense for me to just switch to actionbarsherlock or would I still have all of these problems? – Will Jamieson Mar 03 '15 at 15:50
  • @WillJamieson no need for actionbarsherlock. use the native toolbar available in appcompat v7 – Raghunandan Mar 03 '15 at 15:59
  • @Raghunandando you have any idea about the ActionBarIcon? – Will Jamieson Mar 03 '15 at 19:06

0 Answers0