zoukankan      html  css  js  c++  java
  • 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"> 

            

  • 相关阅读:
    在Idea中使用Eclipse编译器
    Idea切换svn分支,类似Eclipse的Switch功能
    Spring AOP详解
    CGLib动态代理原理及实现
    IDEA下搜狗输入法输入中文时卡着不动的参考解决方法
    Nginx反向代理丢失cookie的问题
    redis连接池自动释放
    Redis常用命令
    waitpid之status意义解析
    bash中管道命令返回值如何确定(下)
  • 原文地址:https://www.cnblogs.com/linxiaojiang/p/3028390.html
Copyright © 2011-2022 走看看