You cannot combine custom titles with other title features

来源:互联网 发布:怎么看淘宝旗舰店执照 编辑:程序博客网 时间:2024/05/17 05:16
使用下面代码自定义标题栏:
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//自定义标题栏
        setContentView(R.layout.main_tijian);

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


在2.3的Android系统上可以运行,在4.0的系统上报如标题所示的错,原因是4.0默认了添一个加标题栏,解决办法:

程序初始为:

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

将        android:theme="@style/AppTheme"

修改为        android:theme="@android:style/Theme.Dialog"

另一种方法为通过actionBar来设置(R.layout.title_bar为自己建立的布局xml文件(也可是自定义的View对象)

ActionBar actionBar = this.getActionBar();
actionBar.setCustomView(R.layout.title_bar);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.show();

0 0
原创粉丝点击