Please help, I can not get icons to appear in action bar.

  • Replies:2
Shelby Simpson
  • Forum posts: 1

Apr 13, 2014, 2:42:55 AM via Website

This is a problem that I have been trying to solve for the last week. I can not get icons to show up in the action bar. They will not show up on an emulators or my phone. In the android studio the search icon shows up in the preview window though. I am at a loss on what to do. I have tried to do this in eclipse also and with several different tutorials. I am probably overlooking something. Any help would be greatly appreciated.
Here is my code -

main.xml(res/menu/main.xml) -
1<menu
2 tools:context="com.example.myapplication3.app.MainActivity" >
3
4 <!-- Search, should appear as action button -->
5 <item android:id="@+id/action_search"
6 android:icon="@drawable/ic_action_search"
7 android:title="@string/action_search"
8 android:showAsAction="ifRoom" />
9 <!-- Settings, should always be in the overflow -->
10 <item android:id="@+id/action_settings"
11 android:title="@string/action_settings"
12 android:showAsAction="never" />
13</menu>

MainActivity - (src/java/MainActivity.) -
1package com.example.myapplication3.app;
2
3import android.support.v7.app.ActionBarActivity;
4import android.os.Bundle;
5import android.view.Menu;
6import android.view.MenuItem;
7
8public class MainActivity extends ActionBarActivity {
9
10 @Override
11 protected void onCreate(Bundle savedInstanceState) {
12 super.onCreate(savedInstanceState);
13 setContentView(R.layout.activity_main);
14 }
15
16
17
18
19 @Override
20 public boolean onCreateOptionsMenu(Menu menu) {
21
22 // Inflate the menu; this adds items to the action bar if it is present.
23 getMenuInflater().inflate(R.menu.main, menu);
24 return true;
25 }
26
27 @Override
28 public boolean onOptionsItemSelected(MenuItem item) {
29 // Handle action bar item clicks here. The action bar will
30 // automatically handle clicks on the Home/Up button, so long
31 // as you specify a parent activity in AndroidManifest.xml.
32 int id = item.getItemId();
33 if (id == R.id.action_settings) {
34 return true;
35 }
36 return super.onOptionsItemSelected(item);
37 }
38
39}

I have the the pics in my drawable folders.

Reply
carlsmileee
  • Forum posts: 19

May 1, 2014, 12:06:57 PM via Website

Try change the setting:
android:showAsAction="always"

Is your device a narrow screen? The action bar have no space to show icon, so move it to overflow. see the follow link
developer.android.com/guide/topics/ui/actionbar.html#ActionItems

— modified on May 1, 2014, 12:07:24 PM

Reply
imla
  • Forum posts: 1

Dec 25, 2014, 7:33:57 AM via Website

...this maybe helpfull to others..
please inser '://'

xmlns:tools="http: schemas.android.com/tools"
xmlns:app="http: schemas.android.com/apk/res-auto"
tools:context=".MyAppName">
android:orderInCategory="100" app:showAsAction="never" />

Reply