Android自定义标题栏

时间:2013-06-28 03:03:08

标签: android custom-titlebar android-titlebar

我一直在尝试自定义标题栏一周。

我已经尝试了大约30条建议来实现这一点,但没有任何效果。

每次尝试时我都会收到you cannot combine custom titles with other title features错误。我无法摆脱这个错误。这让我很生气。

我也试图通过在Google上查找错误来找到解决方案。它也没用。

以下是我尝试过的代码:

this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);

我不知道如何实现自定义标题栏。

非常感谢提前帮助。

2 个答案:

答案 0 :(得分:1)

在我看来,这不是最好的方式。

您应该在res / values / styles.xml中执行以下操作:

<style name="AppBaseTheme" parent="...">
    <item name="android:actionBarStyle">@style/mActionBar</item>
</style>

<style name="mActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">...</item>
        <item name="android:icon">...</item>
        <item name="android:titleTextStyle">...</item>
</style>

答案 1 :(得分:0)

我最近在实现自定义标题栏时遇到了同样的错误......“你无法将自定义标题与其他标题功能结合起来”

根据You cannot combine custom title with other title features,如果项目使用Holo主题,则会显示Holo的标题栏。

我删除了所有使用Holo的代码的项目,然后显示了我的自定义标题栏。