user3195039
user3195039

Reputation:

Items in Action Bar won't show in App

I have a problem: I want to put a search Icon on the Action Bar. In Android Studio it shows it on the Action Bar, but when I open the App it only shows it in the menu..

Here is my xml code:

<item
    android:id="@+id/action_settings"
    android:title="@string/action_settings"
    android:orderInCategory="100"
    android:showAsAction="never" />

<item
    android:id="@+id/action_search"
    android:icon="@drawable/ic_action_search"
    android:showAsAction="ifRoom"
    android:title="@string/action_search"/>

I tried many things but it wont work. I hope you can help me. It still doesn't work I really don't have a clue why.

Upvotes: 0

Views: 931

Answers (2)

Submersed
Submersed

Reputation: 8870

You're not specifying your ActionView class, which is probably part of the problem. Here is the xml for a search action view that I use in one of my applications that works fine.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/search_user"
        android:actionViewClass="android.widget.SearchView"
        android:icon="@drawable/magnifing_glass"
        android:showAsAction="ifRoom|collapseActionView"
        android:title="@string/action_search"/>

</menu>

EDIT:

If you're not trying to use it as an ActionView, disregard the above and use showAsAction="always".

Upvotes: 1

TheIT
TheIT

Reputation: 12219

Your problem is either that there is not enough space on the action bar to display the icon, or your device has a dedicated menu button.

Upvotes: 0

Related Questions