错误提示:java.lang.IllegalArgumentException: Only TabItem instances can be added to TabLayout.


问题描述:在安卓模拟上运行程序时,一打开就报错:xx has stopped.

解决办法:根据错误提示java.lang.IllegalArgumentException: Only TabItem instances can be added to TabLayout.    

查看MainActivity.java代码中  setContentView(R.layout.activity_main);  ,直接去看activity_main.xml 的内容,发现 ViewPager 写在了 TabLayout 里。

提示中明确说到: layout内部不可以放其他东西,只能放tabItem。

改完之后的代码:

<android.support.design.widget.TabLayout
android:id="@+id/mTabLayout"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="@android:color/white"
android:layout_width="match_parent"
android:layout_height="wrap_content">

</android.support.design.widget.TabLayout>

<android.support.v4.view.ViewPager
android:id="@+id/mViewPager"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">

</android.support.v4.view.ViewPager>

结果:已解决


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM