转 Android 4.0后,自定义Title报错 You cannot combine custom titles with other title feature...

本文介绍了在Android应用中自定义Titlebar时遇到的冲突问题及其解决方案。通过修改AndroidManifest.xml和styles.xml文件中的主题设置,可以有效避免与其他标题特性冲突的情况发生。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
自定义Titlebar时为了避免冲突

需要修改:AndroidManifest.xml

android:theme="@style/mystyle" 

styles.xml文件中需要加上下面内容

<style name="mystyle" parent="android:Theme">
<item name="android:windowTitleSize">50dp</item>
</style>

 

 
下面是网上别人的详细分析:
运行项目时,有时LogCat报错: AndroidRuntimeException: You cannot combine custom titles with other title feature


网上说,去掉AndroidManifest.xml中Activity的android:theme="@android:style/Theme.NoTitleBar.Fullscreen"属性。但我看AndroidManifest.xml 根本没有设这个值
[Java]  纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
<application
         android:allowBackup= "true"
         android:icon= "@drawable/ic_launcher"
         android:label= "@string/app_name"
         android:theme= "@style/TitleBarStyle" >
         <activity
             android:name= "com.example.b.MainActivity"
             android:label= "@string/app_name" >
             <intent-filter>
                 <action android:name= "android.intent.action.MAIN" />
 
                 <category android:name= "android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
     </application>



有可能是@style/AppTheme里面设了这个值吧?于是我再看values/styles.xml文件


4.0 即API 14,AppBaseTheme应该在values-v14/style.xml里面的
 

于是我再去看android:Theme.Holo.Light.DarkActionBar 
 

<style name="Theme.Holo.Light.DarkActionBar"> 里面没有关于类似<style name="windowNoTitle">的东西


<style name="Theme.Holo.Light">代码


太多东西了{:soso_e117:},他们引用的东西也不尽相同.....


解决方法:

后来,我直接在 AndroidManifest.xml 中,将android:theme="@style/AppTheme" 直接改成android:theme="@style/android:Theme.Light" (就是不继承API 14中的Theme,用回API 11前的Theme)

或者,删除values-v11和values-v14里面的styles.xml

 
让系统自动调用values/styles.xml

由于API-11的<style name="Theme.Holo.Light"> 和 API-14<style name="Theme.Holo.Light.DarkActionBar"> 跟API之前版本的<style name="Theme.Light"> 代码太多不同了,所以就我也不明白到底哪里出了问题

 

看到别人博客上还有一个解决的方案:

 

在style.xml中修改加入这句“ <item name="android:windowActionBar">false</item>”

 

[html]  view plain copy
 
 
  1. <style name="AppTheme" parent="AppBaseTheme">  
  2.     <!-- All customizations that are NOT specific to a particular API-level can go here. -->  
  3.     <item name="android:windowActionBar">false</item>  
  4. </style>  
 

转载于:https://www.cnblogs.com/wd-one/p/4744203.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值