Android-如何在操作栏上隐藏应用程序图标

Android-如何在操作栏上隐藏应用程序图标,android,android-actionbar,Android,Android Actionbar,我已经实现了右边的菜单(有三个点),左边是导航抽屉 到我使用的应用程序图标: getActionBar().setIcon(R.color.Transparent); 但当应用程序启动时,它会显示图标,然后变为透明,我只想在没有图标的情况下初始化我的应用程序 我还想知道如何将我的应用程序/活动名称置于文本中心 您可以按如下方式编程: getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.

我已经实现了右边的菜单(有三个点),左边是导航抽屉

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

getActionBar().setIcon(R.color.Transparent);
但当应用程序启动时,它会显示图标,然后变为透明,我只想在没有图标的情况下初始化我的应用程序

我还想知道如何将我的应用程序/活动名称置于文本中心


您可以按如下方式编程:

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 
希望有帮助


问候

您可以按如下方式编程:

getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent))); 
希望有帮助


问候

试试这个,actionbar支持

setDisplayShowHomeEnabled(false);

试试这个,actionbar支持

setDisplayShowHomeEnabled(false);
试试这个

actionBar.setDisplayUseLogoEnabled(false);
试试这个

actionBar.setDisplayUseLogoEnabled(false);

我建议你在动作栏上使用一种风格

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

@样式/MyActionBarStyle
@android:彩色/透明
正如您在样式“AppTheme”中看到的,我添加了:

@style/MyActionBarStyle
这表示我希望我的应用程序考虑一个名为“MyActionBarStyle”的自定义动作栏样式

您还可以看到,我声明该样式时使用了:

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

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


本例还假设您正在使用支持库。如果没有,请确保将“AppCompat”替换为“Holo”,将“icon”替换为“android:icon”,将“actionBarStyle”替换为“android:actionBarStyle”。我通过艰苦的方式了解到了这一点:)

我建议你在动作栏上使用一种风格

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

@样式/MyActionBarStyle
@android:彩色/透明
正如您在样式“AppTheme”中看到的,我添加了:

@style/MyActionBarStyle
这表示我希望我的应用程序考虑一个名为“MyActionBarStyle”的自定义动作栏样式

您还可以看到,我声明该样式时使用了:

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

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


本例还假设您正在使用支持库。如果没有,请确保将“AppCompat”替换为“Holo”,将“icon”替换为“android:icon”,将“actionBarStyle”替换为“android:actionBarStyle”。我通过艰苦的方式了解到:)

这个解决方案与我的类似,不起作用。它具有相同的效果:当应用程序启动时,它会显示图标,然后变为透明。此解决方案与我的类似,不起作用。它有同样的效果:当应用程序启动时,它会显示图标,然后变为透明。它解释了定制风格,特别是ActionBar,可以更有效地启动你的应用程序。它解释说,定制风格,特别是ActionBar,可以更高效地启动你的应用程序。它对我起到了作用,替换了你告诉我要替换的内容,加上将“@style/”替换为“android:”,并在清单中将应用程序主题更改为“@style/MyActionBarStyle”。ThanksIt为我工作,替换了您告诉我要替换的内容,加上将“@style/”替换为“android:”,并在清单中将应用程序主题更改为“@style/MyActionBarStyle”。谢谢