将TabLayout与设计API 23.1.0 +

时间:2015-11-26 07:50:10

标签: android android-fragments android-6.0-marshmallow android-tablayout

我在我的应用片段中使用TabLayout。它适用于23.0.0及更低版本的设计API版本,但对于23.1.0和23.2.0,我遇到了以下崩溃:

    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)

当我为片段扩充我的xml布局时,此行发生崩溃:

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

以下是代码中的TabLayout实现:

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);

这是真实的xmls

XML布局片段

<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>

样式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>

0 个答案:

没有答案