如何在styles.xml中设置Action Bar的样式

时间:2013-10-12 07:10:46

标签: android

我想从操作栏中删除应用图标

我不想要那里的主页图标,我想为我的其他图标腾出更多空间:)现在其中4个与右边对齐,第五个只在我按下设置键时显示在底部

我发现这个看起来很有希望的答案

Open your styles.xml file and add below codes in your Actionbar style

<item name="android:displayOptions">showHome|homeAsUp|showTitle</item>
<item name="displayOptions">showHome|homeAsUp|showTitle</item>
<item name="android:icon">@android:color/transparent</item> 

问题是,我不知道他们称之为“你的Actionbar风格”

修改 在这里阅读了一些答案后,我对我的清单做了什么

<application
    android:allowBackup="true"
    android:debuggable="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Sherlock.Light"
    android:theme="@style/CustomActionBarTheme"  >

在最后一行我得到了这个错误:

Attribute "theme" bound to namespace "http://schemas.android.com/apk/res/android" was already specified for element "application".

这是我的styles.xml:

<style name="CustomActionBarTheme">
    <item name="displayOptions">showHome|homeAsUp|showTitle</item>
    <item name="android:icon">@android:color/transparent</item>
</style>

我也试过

    mActionBar.setDisplayHomeAsUpEnabled(false);
    mActionBar.setDisplayShowHomeEnabled(false);
    mActionBar.setDisplayShowTitleEnabled(false);
    mActionBar.setDisplayUseLogoEnabled(false);
    mActionBar.setHomeButtonEnabled(false);

它只会使主图标不可见,但它仍占用空间。为什么他们在这里提供了5种非工作方法,重点是什么?为什么它必须如此令人沮丧。

2 个答案:

答案 0 :(得分:1)

试试这个,

<item name="android:icon">@drawable/ic_menu</item>
<item name="icon">@drawable/ic_menu</item>

所以最后我有这样的事情:

<resources>
<style name="AppTheme" parent="android:Theme.Light" />

<style name="WATheme" parent="Theme.Sherlock.Light">
    <item name="android:actionBarStyle">@style/WATheme.ActionBar</item>
    <item name="actionBarStyle">@style/WATheme.ActionBar</item>
    <item name="android:icon">@drawable/ic_menu</item>
    <item name="icon">@drawable/ic_menu</item>
</style>

<style name="WATheme.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid">
    <item name="android:displayOptions">homeAsUp|showHome|showTitle</item>
    <item name="displayOptions">homeAsUp|showHome|showTitle</item>
</style>
</resources>

答案 1 :(得分:0)

我通过以下方式解决了这个问题: - 删除了我的设置图标 - 然后使我的主页图标看起来像一个设置图标

现在我必须找到一种方法让Home图标打开导航抽屉 而且我还必须找到一种方法来删除主页按钮右侧的巨大空白区域,以便我的图标均匀分布。

相关问题