Reputation: 7073
I have been trying to get action bar icon and for some reason it is not coming at all.
Does the size matters when displaying any icon for action bar?
Mine is: 64*64 px.
My Application Manifest looks like this:
<application
android:allowBackup="true"
android:logo="@mipmap/icon_welcome_logo"
android:icon="@mipmap/icon_welcome_logo"
android:label="@string/app_name"
android:theme="@style/CustomActionBarTheme"
>
I have even tried to set the same through coding, as well as custom style.
Please advise if I am doing anything wrong??
public class MainActivity extends ActionBarActivity {
public static final String TITLE = "Account Details";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle(TITLE);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
Style.xml
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="@style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">@style/MyActionBar</item>
<item name="actionMenuTextColor">@color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar" parent="@style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/TitleTextStyle</item>
<item name="android:background">@color/actionBarBackground</item>
<item name="android:icon">@mipmap/icon_welcome_logo</item>
<item name="android:logo">@mipmap/icon_welcome_logo</item>
<item name="android:displayOptions">useLogo</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">@style/TitleTextStyle</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionBarTextColor</item>
<item name="android:textSize">@dimen/actionBarTextSize</item>
</style>
</resources>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
defaultConfig {
applicationId "au.com.app"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.squareup.dagger:dagger:1.2.1'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.1'
compile 'com.fasterxml.jackson.core:jackson-core:2.5.1'
}
Upvotes: 1
Views: 1356
Reputation: 55517
I believe your issue is similar to https://stackoverflow.com/a/26451433/950427.
Change:
getSupportActionBar().setTitle(TITLE);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);
To:
getSupportActionBar().setTitle(TITLE);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); // <-- added
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Dependency Updates(Unrelated to question):
dependencies {
compile 'com.android.support:appcompat-v7:22.0.0' // <-- Updated
compile 'com.squareup.dagger:dagger:1.2.2' // <-- Updated
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.fasterxml.jackson.core:jackson-databind:2.5.1' // <-- brings in core
}
Upvotes: 4