gpt4 book ai didi

java - 只能与 Theme.AppCompat 主题(或后代)一起使用的 AppCompat 小部件

转载 作者:行者123 更新时间:2023-12-02 02:17:19 31 4
gpt4 key购买 nike

这里的 iOS 开发人员被扔进了 Android 项目的狼群中。我收到一些错误代码,它们都表示类似于 ThemeUtils: View class androidx.appcompat.widget.AppCompatTextView is an AppCompat widget that can only be used with a Theme.AppCompat theme (or descendant). 的内容一旦以下代码 fragment 运行:

view = inflater.inflate(R.layout.f_basic_dashboard_screen, null, false)

我的充气机实例化如下:

val inflater: LayoutInflater = LayoutInflater.from(SqueaksApplication.getApplicationInstance())

SqueaksApplication.getApplicationInstance()只返回 public class SqueaksApplication extends Application 的一个实例

几乎我找到的这个问题的每一个答案都指向项目的 list 作为问题并且需要为项目提供一个主题。我的项目 list 如下所示:

<application
android:name=".SqueaksApplication"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute"
tools:replace="android:icon,android:allowBackup">

如您所见,我的 list 已经包含 android:theme="@style/AppTheme"

我的项目在许多不同的地方使用了布局充气器,但这是我遇到的唯一一个抛出错误的地方。感谢您提供任何见解或解决方案,谢谢!

编辑:根据要求,这是我的 styles.xml:

<style name="MainActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">#FFF</item>
<item name="actionBarStyle">@style/MainActivityTheme.Toolbar</item>
<item name="actionBarTheme">@style/MainActivityTheme.ToolbarOverlay</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="toolbarStyle">@style/MainActivityTheme.Toolbar</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="android:windowBackground">@color/background</item>
<item name="actionOverflowButtonStyle">@style/MainActivityTheme.ActionOverflow</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>

<style name="AlertDialogTheme" parent="Base.Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColorPrimary">#DE000000</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="MainActivityTheme.ActionOverflow" parent="Base.Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_settings</item>
</style>

<style name="MainActivityTheme.Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">@color/colorPrimary</item>
<item name="elevation">4dp</item>
<item name="titleTextAppearance">@style/MainActivityTheme.ToolbarTextAppearance</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
</style>

<style name="MainActivityTheme.ToolbarOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
</style>

<style name="MainActivityTheme.ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">#81be41</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionMenuTextColor">#FFF</item>
<item name="actionBarStyle">@style/Toolbar</item>
<item name="actionBarTheme">@style/ToolbarOverlay</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="toolbarStyle">@style/Toolbar</item>
<item name="android:textColorPrimary">@color/text_primary</item>
<item name="android:textColorSecondary">@color/text_secondary</item>
<item name="android:windowBackground">@color/background</item>
<item name="actionOverflowButtonStyle">@style/ActionOverflow</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>

<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:windowBackground">@color/colorPrimary</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="ActionOverflow" parent="Base.Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/ic_dots_vertical_white</item>
</style>

<style name="Toolbar" parent="Widget.AppCompat.ActionBar.Solid">
<item name="background">@color/colorPrimary</item>
<item name="elevation">4dp</item>
<item name="titleTextAppearance">@style/ToolbarTextAppearance</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
</style>

<style name="ToolbarOverlay" parent="ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@android:color/white</item>
<item name="android:textColorSecondary">@android:color/white</item>
</style>

<style name="ToolbarTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">#81be41</item>
<item name="android:textSize">20sp</item>
</style>

<style name="Splash" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>

<style name="squeak_item_popup_menu_animation">
<item name="android:windowEnterAnimation">@anim/squeak_item_popup_menu_animation_enter</item>
<item name="android:windowExitAnimation">@anim/squeak_item_popup_menu_animation_exit</item>
</style>

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>

最佳答案

您的问题是使用的 context:val inflater: LayoutInflater = LayoutInflater.from(SqueaksApplication.getApplicationInstance())

ApplicationContext 没有您的应用主题。
您需要传递 Activity,而不是 Application Context。

关于java - 只能与 Theme.AppCompat 主题(或后代)一起使用的 AppCompat 小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66968817/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com