无法加载tabLayout

来源:2-1 UI框架搭建

浪子_在路上

2015-12-18 11:38

程序运行不了,有碰到这个问题的吗,求解决方法 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ksw.myapplication/com.ksw.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.TabLayout.TabView

写回答 关注

5回答

  • 乔小欠儿
    2015-12-18 12:37:13
    已采纳

    那个布局文件的代码贴上来看看啊

    浪子_在路上

    布局代码已经贴出来了,能帮我看一下吗

    2015-12-18 22:45:11

    共 1 条回复 >

  • wangjunjia
    2016-08-04 15:47:42
     <android.support.design.widget.TabLayout.TabView        
            android:id="@+id/id_tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabTextColor="#ffffff"
            app:tabIndicatorColor="@color/main_color"
            app:tabSelectedTextColor="@color/main_color">
     
        </android.support.design.widget.TabLayout.TabView>
     <android.support.design.widget.TabLayout
            android:id="@+id/id_tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabTextColor="#ffffff"
            app:tabIndicatorColor="@color/main_color"
            app:tabSelectedTextColor="@color/main_color">
    </android.support.design.widget.TabLayout>


  • 浪子_在路上
    2015-12-18 17:25:37

    全部代码都在这了,该引入的包都引入了,程序编译能通过,就是没法运行

    乔小欠儿

    额...抱歉,我没用过这个组件,这个我没看来问题在哪..

    2015-12-18 23:46:25

    共 1 条回复 >

  • 浪子_在路上
    2015-12-18 17:23:41
    这是布局文件:
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical">
        <android.support.design.widget.TabLayout.TabView
            android:id="@+id/id_tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabTextColor="#ffffff"
            app:tabIndicatorColor="@color/main_color"
            app:tabSelectedTextColor="@color/main_color">
    
        </android.support.design.widget.TabLayout.TabView>
        <android.suport.v4.view.ViewPager
            android:id="@+id/id_viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
    
        </android.suport.v4.view.ViewPager>
    
    
    
    </LinearLayout>

    下面是MainActivity

    package com.ksw.myapplication;
    
    import android.os.Bundle;
    import android.support.design.widget.TabLayout;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentPagerAdapter;
    import android.support.v4.view.ViewPager;
    
    import com.ksw.myapplication.fragement.FestivalCategoryFragment;
    
    public class MainActivity extends FragmentActivity{
        private TabLayout mTabLayout;
        private ViewPager mViewPager;
        private String[] mTitles = new String[]{"节日短信","发送记录"};
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            initViews();
        }
    
        private void initViews() {
             mTabLayout = (TabLayout) findViewById(R.id.id_tabLayout);
             mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
             mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
                 @Override
                 public Fragment getItem(int position) {
                     return new FestivalCategoryFragment();
                 }
    
                 @Override
                 public int getCount() {
                     return mTitles.length;
                 }
    
                 @Override
                 public CharSequence getPageTitle(int position) {
                     return mTitles[position];
                 }
             });
            mTabLayout.setupWithViewPager(mViewPager);
        }
    
    
    }

    FestivalCategoryFragment.java

    package com.ksw.myapplication.fragement;
    
    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.support.v4.app.Fragment;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    
    /**
     * Created by Windows User on 2015/12/18.
     */
    public class FestivalCategoryFragment extends Fragment {
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            return super.onCreateView(inflater, container, savedInstanceState);
        }
    }


  • lynhao
    2015-12-18 13:23:55

    贴上项目代码哦我帮你看看

    浪子_在路上

    代码都在下面了、

    2015-12-18 22:45:56

    共 1 条回复 >

Android-节日短信送祝福(UI篇)

带领大家实现一个节日短信的群发app以及监听短信的发送状态等

21592 学习 · 55 问题

查看课程

相似问题