当前位置: 首页 > 知识库问答 >
问题:

inflating类Android.Support.Design.Widget.BottomNavigationView时出错

柯阳曦
2023-03-14
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".Main2Activity">

    <android.support.design.widget.BottomNavigationView
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        app:menu="@menu/nav_items" />

</RelativeLayout>
package asus.example.com.oop;

import android.os.Bundle; import android.app.Activity;

public class Main2Activity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }

}
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:icon="@drawable/home24"
        android:title="@string/home"
        />

    <item
        android:icon="@drawable/notifications24"
        android:title="@string/notifications"
        />

    <item
        android:icon="@drawable/person24"
        android:title="@string/account"
        />
</menu>

我不知道,为什么我会有这个问题。我添加了compile'com.android.support:design'行来构建gradle,但它仍然不起作用。出什么事了?

共有1个答案

戚逸清
2023-03-14

要使用AppCompat功能,您的活动需要扩展AppCompatactivity

替换

public class Main2Activity extends Activity

public class Main2Activity extends AppCompatActivity
 类似资料: