0

Ok - this one is driving me a little nuts.

I downloaded Android Studio 0.8.14. I created a test app with it and all worked ok.

Since then I've obviously done something because every new App I create is missing the app icon from the action bar when I compile it and run it.

If I change the theme on the activity view page I can see it in the preview but nothing shows up when I run it on my phone.

The original app I created still has the icon present.

My minimum SDK is 9 and my target is 21.

Any ideas anyone?

Thanks

Just to add.. based on advice I have set the minimum SDK to 11 and tried the following but have not had success with either...

    ActionBar actionBar = getActionBar();
    actionBar.setIcon(R.drawable.ic_launcher);

Which causes my app to crash when run (on 4.4)

    ActionBar actionBar = getSupportActionBar();
    actionBar.setIcon(R.drawable.ic_launcher);

Which does nothing.

I'm calling these from my activities on create method.

Thanks in advance

Regnodulous
  • 473
  • 7
  • 22
  • 2
    Although the question is a duplicate neither has actually been answered as yet - or at least been answered with something I can understand so for the moment maybe re-asking is the best way forward. Thanks – Regnodulous Nov 30 '14 at 20:55

1 Answers1

6

That is normal since you support now the new Android version Lollipop. There is the App icon not longer used by default. The new AppCompat library enforce the new material design since the version 21.0.0.

If you want to enforce using the app icon you can set it manually with this line of code:

getSupportActionBar().setIcon(R.drawable.ic_launcher);
rekire
  • 47,260
  • 30
  • 167
  • 264
  • that's great thank you so much. do I put this line in the oncreate of the activity or somewhere else? – Regnodulous Nov 30 '14 at 17:18
  • I would put that in my abstract base class of all activities, but you can put that also directly in all onCreate methods. – rekire Nov 30 '14 at 17:20
  • Any chance you could expand a bit for a noob (sorry). I tried putting this in my oncreate method but nothing happened. I tried getActionBar as well but then my app crashed. I'm not sure how I would add this to the abstract base class in Android Studio. Many thanks – Regnodulous Nov 30 '14 at 20:52
  • Ok figured it out. I created a brand new project, set the min to 14 and the target to 21 and this time using Getactionbar().seticon worked. Doing the same thing on the existing project just kept causing it to crash so go figure. Also setting the minimum to 11 or less and using GetsupportActionbar didn't seem to do anything but the answer above pointed me in the right direction. Thanks for the help. It would still be interesting to know where you can put that code to affect all activities though... – Regnodulous Dec 01 '14 at 00:46