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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,你遇到了一个Android运行时异常:Android.Util.AndroidRuntimeException: 'Only the original thread that created a view hierarchy can touch its views.' 这个异常通常在多线程操作UI界面时出现。在Android中,只有创建视图层次结构的原始线程才能访问和修改视图。 为了解决这个问题,你可以使用以下方法之一: 1. 使用runOnUiThread()方法:这个方法允许你在非UI线程中更新UI。你可以在需要更新UI的地方调用runOnUiThread()方法,并在其中执行UI操作。 ```java runOnUiThread(new Runnable() { public void run() { // 在这里执行UI操作 } }); ``` 2. 使用Handler类:Handler类允许你在非UI线程中发送和处理消息。你可以在非UI线程中创建一个Handler对象,并使用它发送消息到UI线程,然后在UI线程中处理这些消息来更新UI。 ```java Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { public void run() { // 在这里执行UI操作 } }); ``` 3. 使用AsyncTask类:AsyncTask类是Android提供的一个方便的类,用于在后台线程执行异步任务,并在UI线程中更新UI。你可以继承AsyncTask类,并在doInBackground()方法中执行后台任务,在onPostExecute()方法中更新UI。 ```java private class MyTask extends AsyncTask<Void, Void, Void> { protected Void doInBackground(Void... params) { // 在这里执行后台任务 return null; } protected void onPostExecute(Void result) { // 在这里更新UI } } // 在非UI线程中执行任务 new MyTask().execute(); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值