应用程序图标不会显示在Actionbar(Android Studio 1.0.1)中

Tim*_*Tim 5 xml icons android themes

所以我对android开发很新,我只是无法在动作栏中显示任何图标.

我使用最小sdk API 15创建一个新项目,并在Theme-Dropdown(XML-Design-View)中选择"Holo.Light".

所以我希望它看起来像这样:http: //i.stack.imgur.com/zfgCq.png

但它看起来像这样:http: //i.imgur.com/Lmxutct.png

我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
Run Code Online (Sandbox Code Playgroud)

<application
    android:allowBackup="true"
    android:icon="@drawable/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>
Run Code Online (Sandbox Code Playgroud)

我想我必须以某种方式将android:theme更改为Holo.Light?但是没有ressource定义,我似乎无法添加任何..

我的styles.xml:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"/>
    <!-- Customize your theme here. -->
Run Code Online (Sandbox Code Playgroud)

ic_launcher.png位于drawables文件夹中..所以我该怎么办才能显示该死的图标?

(我使用我的HTC一个M8顺便说一句,但它也不会出现在模拟器上)

谢谢!

Joa*_*iba 16

要在ActionBar上显示图标,您必须添加:

getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);
Run Code Online (Sandbox Code Playgroud)

onCreate方法中.

  • 不是那么愚蠢,我从初学者教程开始,你可以改善你的Android开发知识,例如在这样的课程https://www.udacity.com/course/ud853.如果您愿意,可以将答案标记为正确. (2认同)