Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't the app icon in title bar display when I create an app with Android Studio?

Before I created Android App with eclipse, it can display the app icon in the left side of the title bar , please see the image aa.png.

Now I create Android App with Android Studio, I have add the code android:icon="@mipmap/ic_launcher" to manifest.xml file, but the app icon don't display, please see the image bb.png, why?

BTW, The icon can display if I replace compile 'com.android.support:appcompat-v7:22.1.1' with compile 'com.android.support:appcompat-v7:18.0.0', why? are there some bugs with com.android.support:appcompat-v7:22.1.1 ?

aa.png

enter image description here

bb.png

enter image description here

<?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>
like image 348
HelloCW Avatar asked Jul 14 '15 02:07

HelloCW


1 Answers

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

If it doesn't work, you should call getSupportActionBar().setIcon(Drawable/int) or getSupportActionBar().setLogo(Drawable/int)in your Activity.

like image 56
SilentKnight Avatar answered Oct 26 '22 17:10

SilentKnight