android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

为了实现是定义title,我们会加上

requestWindowFeature(Window.FEATURE_CUSTOM_TITLE)和
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.title)这两句代码

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

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

title.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/colorPrimary"
    android:gravity="center_vertical">
<ImageButton
    android:id="@+id/btnBack"
android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/back_icon"
    />

<TextView
    android:id="@+id/lblTitle"
android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:textSize="20sp"
    android:layout_marginLeft="80dip"
    android:textColor="#ffffff"
    />
    <ImageButton
        android:id="@+id/btnGetScanRecord"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        android:background="@mipmap/ic_scan_record"
        android:layout_marginLeft="100dp"
        android:text="扫描记录"/>
    </LinearLayout>

如果出现如下异常:

android.util.AndroidRuntimeException: You cannot combine custom titles with other title features

 

解决方案:

 1、不能用默认主题,需要自定义

 

2、将默认的主题AppTheme改成自定义主题
注意:自定义主题parent必须"Theme.AppCompat"开头,否则仍然报上面的错。我这里选择"Theme.AppCompat.Light.NoActionBar",如果不带"NoActionBar"的主题自定义title和默认的title都会显示。所以要选一款带"NoActionBar"的主题


3、在主题中将   android:windowNoTitle、android:windowActionBar、android:windowActionBarOverlay这三项都设置false

<style name="title_style" parent="Theme.AppCompat.Light.NoActionBar">
      <item name="android:windowNoTitle">false</item> 
      <item name="android:windowActionBar">false</item>
      <item name="android:windowActionBarOverlay">false</item>
      <item name="android:windowTitleSize">44dip</item>
      <item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
    </style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值