无法看到Android操作栏的徽标

时间:2015-03-20 13:44:34

标签: android android-layout android-actionbar

我一直试图获取操作栏图标,但由于某种原因它根本就没有。

在显示操作栏的任何图标时,尺寸是否重要?

我的是:64 * 64像素。

My Application Manifest看起来像这样:

<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"
        >

我甚至尝试通过编码和自定义样式设置相同的内容。

请告知我做错了什么?

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'
}

1 个答案:

答案 0 :(得分:4)

我认为您的问题类似于https://stackoverflow.com/a/26451433/950427

更改:

getSupportActionBar().setTitle(TITLE);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setLogo(R.mipmap.ic_launcher);
getSupportActionBar().setDisplayUseLogoEnabled(true);

getSupportActionBar().setTitle(TITLE);
getSupportActionBar().setDisplayUseLogoEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(true); // <-- added
getSupportActionBar().setIcon(R.drawable.ic_launcher);

依赖性更新(无关紧要):

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
}