I'm new in the Android programming world, and I don't understand why the system is not displaying the application icon on the left side of the 'ActionBar' of my first Android application (HelloWorld).
In the 'ActionBar' developer guide it's stated that: "By default, the system uses your application icon in the action bar, as specified by the icon attribute in the "application" or "activity" element. However, if you also specify the logo attribute, then the action bar uses the logo image instead of the icon." (Action bar)
My Android-manifest file isn't defining a 'logo' attribute, but it defines just an 'icon' attribute. Therefore, the icon defined by the 'icon' attribute should be displayed on the left side of the 'ActionBar' as the application icon. However, no icon is being displayed.
My Android-manifest file is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.holamundo"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And my style files are the following:
/res/values/styles.xml:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
/res/values-v11/styles.xml:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
</resources>
/res/values-v14/styles.xml:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
Can anyone explain me why my application icon is not being displayed in the ActionBar and what should I modify in order to such an icon be displayed? Thanks.
Your activity must extend ActionBarActivity.
For example:
public class MainActivity extends ActionBarActivity
{
...
}
Or try this in your activity:
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setIcon(R.drawable.ic_launcher);
You will have to use getSupportActionBar() if using the support library.