combine custom titles with other title features解决方法

报如下错误:android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

 

这个问题主要是由下面语句造成的。

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);

 

原因暂时不是很清楚,在1,android4.0----2,运行与FragmentActivity子类中会出现,android2.3中应该没有问题,貌似是title的冲突,解决方法如下:

在你的AndroidManifest.xml中添加相应Active的theme。如添加下面语句可解决:

android:theme="@android:style/Theme.Dialog"

具体的theme选项内容的添加根据你自己的意图选择。

虽然上面这样可以在标题栏加入一些控件,但是仍然不能改变标题栏的高度、背景色,要想达到这个目的,只能使用theme(主题)。因此往project里 先添加一个style。改变背景色修改android:windowTitleBackgroundStyle的值,改变标题栏高度则修改 android:windowTitleSize的值。下面是一个示例:

 

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style. name="CustomWindowTitleBackground"> 
        <item name="android:background">#778899</item> 
    </style> 
    <style. name="activityTitlebar" parent="android:Theme"> 
        <item name="android:windowTitleSize">32dp</item> 
        <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item> 
    </style> 
</resources> 

接着再修改AndroidManifest.xml文件,找到要自定义标题栏的Activity,添加上android:theme值,       

<activity android:name=".MainActivity" android:theme="@style/activityTitlebar"> 

        

转载于:https://www.cnblogs.com/linxiaojiang/archive/2013/04/18/3028390.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值