2015-07-14 5 views
6

Bevor ich Android App mit Eclipse erstellt habe, kann es das App-Symbol auf der linken Seite der Titelleiste anzeigen, siehe das Bild aa.png.Warum wird das App-Symbol in der Titelleiste nicht angezeigt, wenn ich eine App mit Android Studio erstelle?

Jetzt erstelle ich Android App mit Android Studio, ich habe den Code android:icon="@mipmap/ic_launcher" zu manifest.xml Datei hinzufügen, aber das App-Symbol nicht angezeigt, siehe das Bild bb.png, warum?

BTW, das Symbol kann angezeigt werden, wenn ich compile 'com.android.support:appcompat-v7:22.1.1' durch compile 'com.android.support:appcompat-v7:18.0.0' ersetzen, warum? Gibt es einige Bugs mit 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> 
+0

Weitere Ideen? Vielen Dank! – HelloCW

Antwort

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> 

Wenn es doesn t arbeiten, sollten Sie getSupportActionBar().setIcon(Drawable/int) oder getSupportActionBar().setLogo(Drawable/int) in Ihrem Activity anrufen.

+0

Danke! aber getSupportActionBar(). setIcon (@ mipmap/ic_launcher); Anzeigefehler – HelloCW

+0

Oh, komm schon. 'setIcon (R.mipmap.ic_launcher)'. – SilentKnight

+0

BTW, Symbol wird nicht angezeigt, nachdem ich Android hinzufügen: Symbol = "@ Mipmap/ic_launcher" HelloCW

2

Mit Android 5.0-Stilen (z. B. AppCompat) wird das App-Symbol nicht in der Aktionsleiste angezeigt.

Sie sollten das App-Symbol sehen können, wenn Sie das Android Holo-Design verwenden. Ändern Sie dazu android: theme auf "android: Theme.Holo" oder "android: Theme.Holo.Light".

Hoffe, das hilft.

+0

Vielen Dank! aber "android: Theme.Holo.Light" erforderlich min API ist 11, jetzt ist meine min API 9. Ich habe "importieren android.support.v7.app.AppCompatActivity" importiert. – HelloCW

Verwandte Themen