迁移到 andoirdx 库后使用 getSupportActionBar

问题描述 投票:0回答:0

我已经将我的项目从 com.android.support:appcompat-v7 库迁移到 androidx.appcompat:appcompat 库,当迁移成功时,应用程序在调用 getSupportActionBar() 时崩溃并出现以下错误:

Caused by: android.view.InflateException: Binary XML file line #27 in 中 hu.neowell.distiller:layout/abc_screen_toolbar: 二进制 XML 文件行 hu.neowell.distiller:layout/abc_screen_toolbar 中的 #27:错误膨胀类 androidx.appcompat.widget.ActionBarContainer

我发现这个 xml 是 v7 appcompat 库的一部分,我猜它也在 androidx 中,但不确定它有什么问题,或者如何解决它。

我一直在使用 Theme.AppCompat.Light 作为我的基本应用程序主题,并使用 getSupportActionBar().setCustomView(R.layout.layout_actionbar);设置我的操作栏。我环顾四周,发现的大多数解决方案都表明您必须向活动布局添加工具栏并首先调用 setSupportActionBar,但如果我仍然可以使用主题中的默认工具栏,我宁愿不更新所有活动在 v7.

有没有办法找出这个 abc_screen_toolbar xml 有什么问题,或者改变一些东西,这样我仍然可以使用 getSupportActionBar 来设置主题工具栏,而无需向我的活动布局添加工具栏?

android android-toolbar androidx
© www.soinside.com 2019 - 2024. All rights reserved.