浪子_在路上
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
那个布局文件的代码贴上来看看啊
<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>
全部代码都在这了,该引入的包都引入了,程序编译能通过,就是没法运行
这是布局文件: <?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); } }
贴上项目代码哦我帮你看看
Android-节日短信送祝福(UI篇)
21592 学习 · 55 问题
相似问题