Reputation: 3270
This is my first time making an Android Actionbar. I just want to add a search image in the bar. But for some reason the image button is not appearing. Here is the Actionbar XML:
<?xml version="1.0" encoding="utf-8"?>
<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="always" />
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:showAsAction="never" />
</menu>
I put showAsAction as true, so the image should appear.
MainActivtiy.java
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
Here is the screen:
Clearly the screen large enough.
and I have the images in the folders. I'm not sure why its not appearing?
Upvotes: 0
Views: 80
Reputation: 653
the following code worked for me this was my menu file res/menu/main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" > <!-- this line matters -->
<item
android:id="@+id/searchItemMenu"
android:icon="@drawable/action_search"
yourapp:showAsAction="ifRoom|withText" <!-- use it here -->
android:title="@string/new_search"/>
</menu>
and in java file
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
Hope this works for you.
Upvotes: 1