My launcher icon is not appearing in my ActionBar, despite having the android:icon
attribute set (and the launcher appearing on my homescreen when I install the app). Note: I am using fragments, and they also contribute action items--but that shouldn't affect the home icon set, correct?
Here is some relevant code from my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://schemas.android.com/apk/res/android"
package="com.mywebsite.myapp">
<application
android:name=".MyApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
...etc...
</activity>
</application>
</manifest>
And the code from styles.xml:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
The code from menu_main.xml, for good measure:
<?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"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<!-- Note: my fragments also contribute action items. -->
<item
android:id="@+id/action_about"
android:orderInCategory="100"
android:title="@string/menu_item_about"
app:showAsAction="never" />
</menu>
And some code from MainActivity.java:
package com.mywebsite.myapp;
import android.support.v7.app.ActionBarActivity;
...etc...
public class MainActivity extends ActionBarActivity {
...lots of code; let me know if you need anything...
// possibly relevant
@Override public boolean onCreateOptionsMenu(Menu menu) {
getMeunInflater().inflate(R.menu.menu_main, menu);
}
}
EDIT: This question is not a duplicate of the question linked to by the moderators. The answer to that question did not solve my problem; the answer I marked as correct below, however, did. To be specific, calling setLogo(int)
was not the solution to my problem. Calling actionBar.setDisplayShowHomeEnabled(true);
, however, did solve my problem. See? Different questions.
Make sure you are displaying it:
actionBar.setDisplayShowHomeEnabled(true);
Then, note that setIcon()
and setLogo()
will only work if you have set displayOptions
accordingly. You can just use:
actionBar.setDisplayOptions(ActionBar.DISPLAY_USE_LOGO);
So your ActionBar
will take your AndroidManifest.xml
's icon. Or:
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.ic_launcher);