当我使用Android Studio创建应用时,为什么标题栏中的应用图标不会显示?

Hel*_*oCW 6 android-studio

在我使用eclipse创建Android应用程序之前,它可以在标题栏的左侧显示应用程序图标,请参阅图像aa.png.

现在我用Android Studio创建Android App,我已经将代码添加android:icon="@mipmap/ic_launcher"到manifest.xml文件中,但是app图标没有显示,请看图像bb.png,为什么?

顺便说compile 'com.android.support:appcompat-v7:22.1.1'一下compile 'com.android.support:appcompat-v7:18.0.0',如果我换了,可以显示图标,为什么?有没有com.android.support:appcompat-v7:22.1.1的错误?

aa.png

在此输入图像描述

bb.png

在此输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.cuiwei.myapplication" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>



apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.cuiwei.myapplication"
        minSdkVersion 9
        targetSdkVersion 22
        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:22.1.1'
}

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>
Run Code Online (Sandbox Code Playgroud)

Sil*_*ght 3

<activity
        android:name=".MainActivity"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

如果它不起作用,您应该getSupportActionBar().setIcon(Drawable/int)getSupportActionBar().setLogo(Drawable/int)您的Activity.