0
votes

I am following step by step instructions shared on development platform of google http://developer.android.com/training/basics/actionbar/index.html

But some how due to some reason I am not seeing ic_action_search.png on Menu bar in my simulator, though it is imported and copied on drawable-hdpi.

Listing down all options tried till now (using eclipse IDE):

  1. Import image ic_action_search.png
  2. Don't import image but copy it directly on folder
  3. Size of image, I have copied it directly from Android_Design_Icons.zip suggested at https://developer.android.com/design/downloads/index.html
  4. Recompile project by "Clean"
  5. Deleting res in bin folder
  6. Deleting R.java in gen folder
  7. Creating whole project altogether again
  8. Changing option android:showAsAction to "never", "always", "ifRoom"
  9. Placing .png file at right place
  10. Not using .jpg only .png
  11. Using Support library
  12. Using lower case to define file names
  13. Added following to menu tag, xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.actionbar.MainActivity"
  14. Added follwoing to item tag android:actionViewClass="android.widget.SearchView"

My main_activity_actions.xml looks like,

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- Search, should appear as action button -->
  <item android:id="@+id/action_search"
      android:icon="@drawable/ic_action_search"
      android:title="@string/action_search"
      android:showAsAction="never" />
 <item android:id="@+id/action_settings"
      android:title="@string/action_settings"
      android:showAsAction="never" /></menu>

.... but still I cant see search image getting loaded up in menu bar. Though settings icon shows the action_search value defined in string.xml I am not using Support Library Setup as of now, and android:minSdkVersion="11" android:targetSdkVersion="19"

I need to show this, as there is something wrong here and as i go further I still cant load any other image. Please advise

2

2 Answers

0
votes

You need to change the showAsAction as always or ifRoom to show the action icons in the menu bar. If you set it to never , it will not be shown as an action menu. It will only show in PopupMenu

Change

 android:showAsAction="never"

to

 android:showAsAction="always"
0
votes

append this line in your menu tag xmlns:yourapp="http://schemas.android.com/apk/res-auto" and append these two lines in item tag

 yourapp:actionViewClass="android.widget.SearchView"
            yourapp:showAsAction="always"

i.e. use this layout

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
    <!-- Search / will display always -->
    <item android:id="@+id/action_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/action_search"
          android:actionViewClass="android.widget.SearchView"
          yourapp:actionViewClass="android.widget.SearchView"
            yourapp:showAsAction="always"
          android:showAsAction="always"/>