当前位置: 动力学知识库 > 问答 > 编程问答 >

android - App crash while using TabLayout with design API 23.1.0+

问题描述:

I am using TabLayout inside a fragment of my app. It works OK with design API version of 23.0.0 and below but for 23.1.0 and 23.2.0 I have the following crash:

 11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: FATAL EXCEPTION: main

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: Process:

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: android.view.InflateException: Binary XML file line #10: Binary XML file line #10: Error inflating class android.support.design.widget.TabLayout

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:539)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.LayoutInflater.inflate(LayoutInflater.java:423)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at fragment.PrizeListFragment.onCreateView(PrizeListFragment.java:148)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.Fragment.performCreateView(Fragment.java:2220)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:973)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1148)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.BackStackRecord.run(BackStackRecord.java:793)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1535)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:562)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.support.v13.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:1106)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.support.v4.view.ViewPager.populate(ViewPager.java:952)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.View.measure(View.java:18788)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.View.measure(View.java:18788)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.View.measure(View.java:18788)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:446)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.View.measure(View.java:18788)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.View.measure(View.java:18788)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:670)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:606)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)

11-26 16:03:42.528 7794-7794/E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)

11-26 16:03:42.528 7794-7794/ E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Crash occurs at this line when i inflate my xml layout for the fragment:

View fragmentView = inflater.inflate(R.layout.fragment_prize_list, container, false);

Here is my TabLayout implementation in code:

TabLayout tabLayout = (TabLayout) fragmentView.findViewById(R.id.sliding_tabs_type);

tabLayout.setTabTextColors(getResources().getColor(R.color.text_gray), getResources().getColor(R.color.theme_light_blue));

tabLayout.setupWithViewPager(viewPager);

Here are the realted xmls

XML Layout Fragment

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="@android:color/transparent">

<android.support.design.widget.TabLayout

android:id="@+id/sliding_tabs_type"

android:layout_width="match_parent"

android:layout_height="40dp"

app:tabGravity="fill"

android:background="@color/white"

app:tabTextAppearance="@style/TabLayoutPrizeType.Text"

style="@style/TabLayoutPrizeType"/>

<android.support.v4.view.ViewPager

android:id="@+id/vp_prize"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@android:color/white" />

</LinearLayout>

Styles xml

<style name="TabLayoutPrizeType" parent="Widget.Design.TabLayout">

<item name="tabIndicatorColor">@color/semi_theme_blue</item>

</style>

<style name="TabLayoutPrizeType.Text" parent="TextAppearance.Design.Tab">

<item name="android:textSize">15sp</item>

</style>

分享给朋友:
您可能感兴趣的文章:
随机阅读: