无法将android.support.v7.widget.AppCompatTextView转换为android.widget.ImageView
以下是activity_main.xml文件:无法将android.support.v7.widget.AppCompatTextView转换为android.widget.ImageView,android,android-tablayout,tabitem,Android,Android Tablayout,Tabitem,以下是activity_main.xml文件: <?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
<?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"
android:orientation="vertical"
tools:context="com.issaayoub.materialtest.MainActivity">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:elevation="4dp">
<android.support.design.widget.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:icon="@drawable/an"
android:text="@string/bird1" />
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/tabLayout">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="com.issaayoub.materialtest.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
请有人强调一下TabItem有什么问题
删除TabItem将删除所有此错误。最后,请注意,应用程序在手机/模拟器上正常运行,没有任何错误
谢谢你的帮助 ,我认为这里只能给出文本或图标,不能同时给出两者
<android.support.design.widget.TabLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.design.widget.TabItem
android:text="@string/tab_text"/>
<android.support.design.widget.TabItem
android:icon="@drawable/ic_android"/>
</android.support.design.widget.TabLayout>
试试看。什么都没用。我重新启动了Android Studio,错误被删除。
请注意,我们可以同时添加文本和图标。
以下是应用程序布局图:
请发布您的MainActivity
code您可以发布MainActivity.class
code MainActivity.class没有任何效果,因为我以前做的是:添加TabItem,然后出现错误,然后删除TabItem,然后删除错误。因此,这与MainActivity类中的Java代码无关。请注意,您可以向ItemTab添加图标和文本。我使用自定义选项卡项添加图像和文本,但不知道可以直接添加。谢谢你
<android.support.design.widget.TabLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<android.support.design.widget.TabItem
android:text="@string/tab_text"/>
<android.support.design.widget.TabItem
android:icon="@drawable/ic_android"/>
</android.support.design.widget.TabLayout>