简体   繁体   English

Android - 如何在操作栏中显示应用徽标

[英]Android - How to show App logo in action bar

The theme of my application is Light.我的应用程序的主题是 Light。 Can I display app icon in action bar without changing app style from Theme.Light to Theme.Holo.Light.我可以在不将应用程序样式从 Theme.Light 更改为 Theme.Holo.Light 的情况下在操作栏中显示应用程序图标吗?

style.xml样式文件

<style name="AppBaseTheme" parent="android:Theme.Light">

AndroidManifest.xml AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:logo="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

The styles of "EditText" and etc object more beautiful with Theme.Light, that why I don't want to change it. “EditText”等对象的样式与 Theme.Light 更美观,这就是为什么我不想改变它。 It is possible or I should write style for each object and change theme of application.有可能或者我应该为每个对象编写样式并更改应用程序的主题。

This works for me with Theme.Light这对我有用 Theme.Light

android.support.v7.app.ActionBar menu = getSupportActionBar();
menu.setDisplayShowHomeEnabled(true);
menu.setLogo(R.drawable.ic_launcher);
menu.setDisplayUseLogoEnabled(true);

The actionbar uses the android:logo attribute from manifest file.操作栏使用清单文件中的 android:logo 属性。 Then use setDisplayUseLogoEnabled() to set it in the ActionBar然后在ActionBar中使用setDisplayUseLogoEnabled()进行设置

Try like this像这样尝试

 getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME |
                ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_HOME_AS_UP | 
                ActionBar.DISPLAY_USE_LOGO);
 getSupportActionBar().setIcon(R.drawable.search_icon);
 getSupportActionBar().setDisplayUseLogoEnabled(true);

This works well for me:这对我很有效:

//show the icon
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setIcon(R.drawable.ic_launcher);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM