2

I implemented a basic activity as

public class MainActivity extends Activity

and when I add an actionbar with the menu as below, the app icon defined in the AndroidManifest.xml shows up nicely

<application
android:allowBackup="true"
android:icon="@drawable/logo_green"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >

When I try to change to android.support.v7.app.ActionBarActivity ( and switch to compatible AppCompat theme like @style/Theme.AppCompat.Light.DarkActionBar) the main app menu in the action bar strangely disappears

I tried getting it back to where it should be in the Oncreate() method but it does not work

actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setIcon(R.drawable.green_drawable);

action bar xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <!-- Search / will display always -->


    <item android:id="@+id/notification"
        android:icon="@drawable/notification_active"
        android:title="Setup"
        app:showAsAction="never"/>

    <item android:id="@+id/action_search"
        android:icon="@drawable/add_friends"
        android:title="Add Friends"
        app:showAsAction="never"/>


    <item android:id="@+id/action_setup"
        android:icon="@drawable/trackingicon"
        android:title="Setup"
        app:showAsAction="never"/>

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

    <item android:id="@+id/action_help"
        android:icon="@drawable/helpicon"
        android:title="Contact Support"
        app:showAsAction="ifRoom"/>


</menu>
dowjones123
  • 3,695
  • 5
  • 40
  • 83

1 Answers1

25

setIcon/setLogo method will only work if you have set DisplayOptions Try this -

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.ic_launcher);

You can also set options for displaying LOGO(just add constant ActionBar.DISPLAY_USE_LOGO). More information - displayOptions

Vintesh
  • 1,657
  • 1
  • 24
  • 31
  • 2
    I've been forever searching for this answer! Thank you. – midiwriter Jan 09 '15 at 00:13
  • @Vintesh but it leaves blank space to left of icon. How to remove this space? Thanks! – Programmer Apr 17 '15 at 12:56
  • If i am understanding correct then, you should try [1](http://stackoverflow.com/questions/27354812/android-remove-left-margin-from-actionbars-custom-layout) or [2](http://stackoverflow.com/questions/16026007/remove-padding-around-action-bar-left-icon-on-android-4-0) or creating custom toolbar will surely work. – Vintesh Apr 17 '15 at 16:23