Android有关自定义标题的问题 You cannot combine custom titles with other title features

在Activity里面添加代码:

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

问题现象如下:

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.qqlogin/com.example.qqlogin.MainActivity}: android.util.AndroidRuntimeException: <span style="color:#ff0000;">You cannot combine custom titles with other title features</span>
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2114)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2139)
at android.app.ActivityThread.access$700(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4963)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(Native Method)
<span style="color:#ff0000;">Caused by: android.util.AndroidRuntimeException: You cannot combine custom titles with other title features</span>
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:289)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:3118)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3358)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:314)
at android.app.Activity.setContentView(Activity.java:1924)
at com.example.qqlogin.MainActivity.onCreate(MainActivity.java:30)
at android.app.Activity.performCreate(Activity.java:5184)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2078)
... 11 more

这个问题是在manifest添加activity未添加主题

        <activity
            android:name="com.example.qqlogin.MainActivity" >   <span style="color:#3333ff;">//此处必须添加主题,不然就报错</span>
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

使用系统自带的主题:android:theme="@style/android:Theme.Light"

使用主题样式@style 


android:Theme:

android:theme="@android:style/Theme.Dialog" : Activity显示为对话框模式

android:theme="@android:style/Theme.NoTitleBar" : 不显示应用程序标题栏

android:theme="@android:style/Theme.NoTitleBar.Fullscreen" : 不显示应用程序标题栏,并全屏

android:theme="Theme.Light ": 背景为白色

android:theme="Theme.Light.NoTitleBar" : 白色背景并无标题栏

android:theme="Theme.Light.NoTitleBar.Fullscreen" : 白色背景,无标题栏,全屏

android:theme="Theme.Black" : 背景黑色

android:theme="Theme.Black.NoTitleBar" : 黑色背景并无标题栏

android:theme="Theme.Black.NoTitleBar.Fullscreen" : 黑色背景,无标题栏,全屏

android:theme="Theme.Wallpaper" : 用系统桌面为应用程序背景

android:theme="Theme.Wallpaper.NoTitleBar" : 用系统桌面为应用程序背景,且无标题栏

android:theme="Theme.Wallpaper.NoTitleBar.Fullscreen" : 用系统桌面为应用程序背景,无标题栏,全屏

android:theme="Theme.Translucent : 透明背景

android:theme="Theme.Translucent.NoTitleBar" : 透明背景并无标题

android:theme="Theme.Translucent.NoTitleBar.Fullscreen" : 透明背景并无标题,全屏

android:theme="Theme.Panel ": 面板风格显示

android:theme="Theme.Light.Panel" : 平板风格显示




android:Theme.Light  使用这个不会报错

------- AppBaseTheme 使用这个同样报错

------- AppTheme 使用这个同样报错

使用自己的主题也可以:android:theme="@style/titlebarstyle" 自定义的主题样式一定要继承系统主题

    <style name="CustomizedWindowTitleBackground">  
		<item name="android:background">#047BF0</item>   
    </style>
     
     <style name="titlebarstyle"<span style="color:#000099;"> <strong>parent="android:Theme</strong>"</span>>      
            <item name="android:windowTitleSize">48dp</item>      
            <item name="android:windowTitleBackgroundStyle">@style/CustomizedWindowTitleBackground</item> 
    </style> 


       <activity android:name="MainActivity" <span style="color:#ff0000;">android:theme="@style/android:Theme.Light"</span>>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值