没有找到类错误膨胀类android.support.design.widget.BottomNavigationView

时间:2017-08-14 10:30:04

标签: java android xml android-layout

我缺少什么?我跟进了这些答案error-inflating-class-androidsupport-design-widget-navigationview。但仍然得到这个错误

 Error inflating class android.support.design.widget.BottomNavigationView
Didn't find class "android.support.design.widget.BottomNavigationView" on path: DexPathList[[zip file ...

我的MainActivity包括AppCompatActivity:

public class MainActivity extends AppCompatActivity   implements NavigationView.OnNavigationItemSelectedListener {

我的朋友是:

compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:recyclerview-v7:23.0.+'

我的风格是:

<!-- Base application theme. -->
<style name="AppTheme" parent="Base.AppTheme">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="Base.AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="android:colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="Theme.AppCompat.Light.DarkActionBar" />

<style name="AppTheme.PopupOverlay" parent="Theme.AppCompat.Light.DarkActionBar" />

我的xml是:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/liner1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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


    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_above="@+id/recyclerview1"
        android:gravity="center"
        android:background="#10bcc9"
        android:textColor="@android:color/white"
        android:text="New Games." />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview1"
        android:layout_width="wrap_content"
        android:layout_height="140dp"
        android:scrollbars="horizontal" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_below="@+id/recyclerview1"
        android:gravity="center"
        android:background="#10bcc9"
        android:textColor="@android:color/white"
        android:text="Used Games." />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/maingridrc"
        android:layout_width="wrap_content"
        android:layout_height="330dp"
        android:layout_marginTop="5dp"
        android:scrollbars="vertical" />

  <!--  <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />-->
</LinearLayout>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    app:menu="@menu/my_navigation_items" />

</RelativeLayout>
SDK管理器中的

enter image description here

2 个答案:

答案 0 :(得分:4)

迁移到AndroidX后,替换

android.support.design.widget.BottomNavigationView

使用

com.google.android.material.bottomnavigation.BottomNavigationView

答案 1 :(得分:2)

BottomNavigationView仅添加到支持库修订版25.0.0中。

https://developer.android.com/topic/libraries/support-library/revisions.html#rev25-0-0

您使用的是旧版本:

compile 'com.android.support:design:23.1.1'

将您用于版本25.0.0所有支持库