【问题标题】:Android - How do i hide the app icon on action barAndroid - 如何隐藏操作栏上的应用程序图标
【发布时间】:2017-10-22 07:52:06
【问题描述】:

我已经实现了右侧菜单(三个点)和左侧的抽屉式导航。

到我使用的应用程序图标:

getActionBar().setIcon(R.color.Transparent);

但碰巧当应用程序启动时它会显示图标,然后它会变成透明的,我想简单地初始化我的应用程序而没有图标。

我也想知道如何将文本与我的应用/活动名称居中。

【问题讨论】:

标签: android android-actionbar


【解决方案1】:

我建议您为操作栏使用一种样式。

在您的 values 文件夹下的 styles.xml 文件中,您可以对其进行编辑,以便 AppTheme 为您的操作栏使用特定样式。在该特定样式中,您可以声明您的图标属性。这让操作栏从一开始就知道您有一个特定的图标,并将显示它以消除临时暂停。

styles.xml

<resources>

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
</style>   


<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="icon">@android:color/transparent</item>
</style>
</resources>

正如您在我添加的样式“AppTheme”中看到的那样:

<item name="actionBarStyle">@style/MyActionBarStyle</item>

这表明我希望我的应用考虑到名为“MyActionBarStyle”的操作栏的自定义样式

您还可以看到我用以下方式声明该样式:

<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <item name="icon">@android:color/transparent</item>
</style>

在此声明中,我可以将图标设置为可绘制或颜色(就像我们在本例中所做的那样)。希望这会有所帮助。

此示例还假设您正在使用支持库。如果不是,那么只需确保将“AppCompat”替换为“Holo”,将“icon”替换为“android:icon”,将“actionBarStyle”替换为“android:actionBarStyle”。我很难学到这一点:)

【讨论】:

  • 它对我有用,方法是替换您告诉我要替换的内容,加上将“@style/”替换为“android:”,并在清单中将应用程序主题更改为“@style/MyActionBarStyle”。谢谢
【解决方案2】:

您可以按以下方式编程:

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 

希望对你有帮助!

问候!

【讨论】:

  • 此解决方案与我的类似,但不起作用。它具有相同的效果:当应用启动时,它会显示图标,然后变为透明。
【解决方案3】:

试试这个,actionbar 支持,

setDisplayShowHomeEnabled(false);

【讨论】:

    【解决方案4】:

    试试这个,

    actionBar.setDisplayUseLogoEnabled(false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      相关资源
      最近更新 更多