【问题标题】:Android - How to show App logo in action barAndroid - 如何在操作栏中显示应用程序徽标
【发布时间】:2013-10-23 11:40:30
【问题描述】:

我的应用程序的主题是 Light。我可以在操作栏中显示应用图标而不将应用样式从 Theme.Light 更改为 Theme.Holo.Light。

style.xml

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

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

“EditText”等对象的样式用 Theme.Light 更漂亮,这就是我不想改变它的原因。有可能或者我应该为每个对象编写样式并更改应用程序的主题。

【问题讨论】:

    标签: android themes graphical-logo


    【解决方案1】:

    这适用于我的 Theme.Light

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

    【讨论】:

      【解决方案2】:

      操作栏使用清单文件中的 android:logo 属性。然后使用 setDisplayUseLogoEnabled() 在 ActionBar 中设置

      【讨论】:

      • 当我的应用程序主题是“Theme.Light”和 onCreate 函数我写 getActionBar().setDisplayUseLogoEnabled(true);应用程序崩溃。我没听错吗?
      • 您的代码是否可以在没有进行任何徽标相关设置的情况下使用操作栏?
      • 如果我在主题中写这个&lt;style name="AppBaseTheme" parent="android:Theme.Holo.Light"&gt; 它也会显示徽标,但是我不想拥有的主题。在这种情况下,我也可以写getActionBar().setDisplayUseLogoEnabled(true)。我需要知道是否存在任何在操作栏中显示徽标而不将 Theme.Light 主题更改为 Theme.Holo.Light 的方式?
      • 有谁知道 Kotlin 的用法吗?
      【解决方案3】:

      这样试试

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

      【讨论】:

        【解决方案4】:

        这对我很有效:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-01-06
          • 1970-01-01
          相关资源
          最近更新 更多