gpt4 book ai didi

android - 即使在为 TabLayout 创建样式后,也会发生错误膨胀类 android.support.design.widget.TabLayout

转载 作者:行者123 更新时间:2023-11-29 19:53:15 27 4
gpt4 key购买 nike

我已经尝试过应该使它工作的解决方案(自定义样式):

文件夹res\values-v21\styles.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base"/>
<!-- inherit from material theme -->
<style name="AppTheme.Base" parent="android:Theme.Material">
<!-- colorPrimary is used for the default action bar background -->
<item name="android:colorPrimary">#3F51B5</item>

<!-- colorPrimaryDark is used for the status bar -->
<item name="android:colorPrimaryDark">#303F9F</item>

<!-- colorAccent is used for the default value for colorControlActivated
which is used to tint widgets -->
<item name="android:colorAccent">#FF4081</item>
</style>

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#DD4081</item>
</style>

</resources>

myFragment.xml 中的选项卡布局:

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
style="@style/MyCustomTabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

*使用编译'com.android.support:design:+'

backtrace 来自 Crashlytics(自从我迁移到 Android Studio 后,我无法像在 Eclipse 中那样看到那里的堆栈跟踪。Logcat 会打印一些内容,但不会打印实际的崩溃异常):

android.view.LayoutInflater.inflate (LayoutInflater.java:539)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
com.<package>.MyFragment.onCreateView (MyFragment.java:402)
android.app.Fragment.performCreateView (Fragment.java:2220)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:973)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1148)
android.app.BackStackRecord.run (BackStackRecord.java:793)
android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1535)
android.app.FragmentManagerImpl$1.run (FragmentManager.java:482)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5417)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

然后还有:

Caused by java.lang.IllegalArgumentException
android.support.design.widget.ThemeUtils.checkAppCompatTheme (ThemeUtils.java:34)
android.support.design.widget.TabLayout.<init> (TabLayout.java:269)
android.support.design.widget.TabLayout.<init> (TabLayout.java:263)
java.lang.reflect.Constructor.newInstance (Constructor.java)
android.view.LayoutInflater.createView (LayoutInflater.java:619)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:764)
android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:704)
android.view.LayoutInflater.rInflate (LayoutInflater.java:835)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
android.view.LayoutInflater.rInflate (LayoutInflater.java:838)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
android.view.LayoutInflater.rInflate (LayoutInflater.java:838)
android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:798)
android.view.LayoutInflater.inflate (LayoutInflater.java:515)
android.view.LayoutInflater.inflate (LayoutInflater.java:423)
com.<package>.MyFragment.onCreateView (MyFragment.java:402)
android.app.Fragment.performCreateView (Fragment.java:2220)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:973)
android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1148)
android.app.BackStackRecord.run (BackStackRecord.java:793)
android.app.FragmentManagerImpl.execPendingActions (FragmentManager.java:1535)
android.app.FragmentManagerImpl$1.run (FragmentManager.java:482)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:148)
android.app.ActivityThread.main (ActivityThread.java:5417)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

最佳答案

AppCompat 元素(如 TabLayout)通过检查当前主题是否已定义“colorPrimary”属性来检查它们是否位于具有 Theme.AppCompat 主题的 Activity 中。您使用了“android”命名空间中的“colorPrimary”属性,这不是 AppCompat 使用的属性。添加 <item name="colorPrimary">#3F51B5</item> (没有 android 命名空间)到您的 Activity 主题。

关于android - 即使在为 TabLayout 创建样式后,也会发生错误膨胀类 android.support.design.widget.TabLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36937748/

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