这个布局文件一直报错。

时间:2022-08-31 11:04:26
一直报android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class <unknown>
。求大神教育。。。我想实现底部按钮加侧边菜单!谢谢!


<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <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"
        tools:context=".StoreActivity" >

        <LinearLayout
            android:orientation="vertical"
            android:id="@+id/show_list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </LinearLayout>

        <com.ashokvarma.bottomnavigation.BottomNavigationBar
            android:id="@+id/bottom_navigation_bar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_alignParentBottom="true"/>

    </RelativeLayout>

    <ListView
        android:id="@+id/list_drawer"
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:drawSelectorOnTop="false">
    </ListView>

</android.support.v4.widget.DrawerLayout>




package com.ishihara.satomi;

import android.app.ActionBar;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ikimuhendis.ldrawer.ActionBarDrawerToggle;
import com.ikimuhendis.ldrawer.DrawerArrowDrawable;

public class StoreActivity extends Activity{

    int lastSelectedPosition = 0;
    private BottomNavigationBar bottomNavigationBar;

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;
    private DrawerArrowDrawable drawerArrow;
    private boolean drawerArrowColor;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.atylist);

        ActionBar ab = getActionBar();
        ab.setDisplayHomeAsUpEnabled(true);
        ab.setHomeButtonEnabled(true);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.list_drawer);


        drawerArrow = new DrawerArrowDrawable(this) {
            @Override
            public boolean isLayoutRtl() {
                return false;
            }
        };
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                drawerArrow, R.string.drawer_open,
                R.string.drawer_close) {

            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerToggle.syncState();


        String[] values = new String[]{
                "Stop Animation (Back icon)",
                "Stop Animation (Home icon)",
                "Start Animation",
                "Change Color",
                "GitHub Page",
                "Share",
                "Rate"
        };
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);
        mDrawerList.setAdapter(adapter);
        mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                switch (position) {
                    case 0:
                        System.out.println(position);
                        break;
                    case 1:
                        System.out.println(position);
                        break;
                    case 2:
                        System.out.println(position);
                        break;
                    case 3:
                        System.out.println(position);
                        break;
                    case 4:
                        System.out.println(position);
                        break;
                    case 5:
                        System.out.println(position);
                        break;
                    case 6:
                        System.out.println(position);
                        break;
                }
            }
        });

        bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);

        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.drawable.ic_home_white_24dp, "Home"))
                .addItem(new BottomNavigationItem(R.drawable.ic_book_white_24dp, "Books"))
                .addItem(new BottomNavigationItem(R.drawable.ic_music_note_white_24dp, "Music"))
                .addItem(new BottomNavigationItem(R.drawable.ic_tv_white_24dp, "Movies"))
                .addItem(new BottomNavigationItem(R.drawable.ic_videogame_asset_white_24dp, "Games"))
                .setFirstSelectedPosition(lastSelectedPosition)
                .initialise();
        bottomNavigationBar.setMode(BottomNavigationBar.MODE_CLASSIC);
        bottomNavigationBar.setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_RIPPLE);
        bottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {

            @Override
            public void onTabSelected(int position) {
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
                switch (position) {
                    case 0:
                        beginTransaction.replace(R.id.show_list_view, new HomeFragment());
                        break;
                    case 1:
                        beginTransaction.replace(R.id.show_list_view, new BooksFragment());
                        break;
                    case 2:
                        beginTransaction.replace(R.id.show_list_view, new MusicFragment());
                        break;
                    case 3:
                        beginTransaction.replace(R.id.show_list_view, new MoviesFragment());
                        break;
                    case 4:
                        beginTransaction.replace(R.id.show_list_view, new GamesFragment());
                        break;
                    default:
                        break;
                }
                beginTransaction.commit();
            }

            @Override
            public void onTabUnselected(int position) {
            }

            @Override
            public void onTabReselected(int position) {
            }
        });
        setDefaultFragment();
    }

    private void setDefaultFragment() {
        FragmentManager fm = getFragmentManager();
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.replace(R.id.show_list_view, new HomeFragment());
        transaction.commit();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            if (mDrawerLayout.isDrawerOpen(mDrawerList)) {
                mDrawerLayout.closeDrawer(mDrawerList);
            } else {
                mDrawerLayout.openDrawer(mDrawerList);
            }
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
}

6 个解决方案

#1


com.ashokvarma.bottomnavigation.BottomNavigationBar  这可不是现成的写法, 楼主是写了这么一个类吗?

#2


引用 1 楼 tcmakebest 的回复:
com.ashokvarma.bottomnavigation.BottomNavigationBar  这可不是现成的写法, 楼主是写了这么一个类吗?

对的,这是一个现成的底部菜单栏。我直接拿过来用的。

#3


感觉应该是包导入的有问题

#4


楼主解决没,我也是出现这种错误

#5


不知道楼主解决没,可否分享

#6


进来看一下~!请问<br 跟html语言的</br>是不是都是换行的意思?

#1


com.ashokvarma.bottomnavigation.BottomNavigationBar  这可不是现成的写法, 楼主是写了这么一个类吗?

#2


引用 1 楼 tcmakebest 的回复:
com.ashokvarma.bottomnavigation.BottomNavigationBar  这可不是现成的写法, 楼主是写了这么一个类吗?

对的,这是一个现成的底部菜单栏。我直接拿过来用的。

#3


感觉应该是包导入的有问题

#4


楼主解决没,我也是出现这种错误

#5


不知道楼主解决没,可否分享

#6


进来看一下~!请问<br 跟html语言的</br>是不是都是换行的意思?