【问题标题】:Why don't the app icon in title bar display when I create an app with Android Studio?为什么我使用 Android Studio 创建应用时,标题栏中的应用图标不显示?
【发布时间】:2015-07-14 02:30:40
【问题描述】:

在我用eclipse创建Android App之前,它可以在标题栏左侧显示app图标,请看图片aa.png。

现在我用Android Studio创建Android App,我在manifest.xml文件中添加了代码android:icon="@mipmap/ic_launcher",但是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>

【问题讨论】:

  • 还有什么想法吗?谢谢!

标签: android-studio


【解决方案1】:
<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>

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

【讨论】:

  • 谢谢!但是 getSupportActionBar().setIcon(@mipmap/ic_launcher);显示错误
  • 哦,来吧。 setIcon(R.mipmap.ic_launcher).
  • 顺便说一句,我将 android:icon="@mipmap/ic_launcher" 添加到 后图标不显示
  • 所以您需要以编程方式进行。
  • 谢谢!我已经添加了代码 setIcon(R.mipmap.ic_launcher) ,但是图标还没有显示
【解决方案2】:

使用 Android 5.0 样式(即 AppCompat),应用图标不会显示在操作栏中。

如果您使用 Android Holo 主题,您应该能够看到应用图标。为此,请将 android:theme 更改为“android:Theme.Holo”或“android:Theme.Holo.Light”。

希望这会有所帮助。

【讨论】:

  • 谢谢!但“android:Theme.Holo.Light”所需的最小 API 为 11,现在我的最小 API 为 9。我已导入“import android.support.v7.app.AppCompatActivity”。
猜你喜欢
  • 1970-01-01
  • 2015-03-04
  • 1970-01-01
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-28
相关资源
最近更新 更多