NavigationDrawer与ActionBarSherlo

NavigationDrawer与ActionBarSherlo

本文介绍了NavigationDrawer与ActionBarSherlok的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿我试图使用 DrawerLayout ActionBarSherlok 但是我得到的错误

Hey I am trying to use DrawerLayout with ActionBarSherlok but i am getting error

15 06-30:37:18.874:E / AndroidRuntime(1305):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.Priyesh / com.Priyesh.MainActivity}:android.view.InflateException:二进制XML文件行#1:错误充气类android.support.v4.widget.DrawerLayout

这里是我的xml文件

<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" >

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />


<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#111"
    android:choiceMode="singleChoice"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp" />

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

package com.example;

import java.util.ArrayList;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.actionbarsherlock.app.*;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;

public class MainActivity extends  SherlockActivity {
DrawerLayout mydrawerlayout;
ListView drawerlist;
ArrayList<String> mplanetlist;
ActionBarDrawerToggle drawer_toggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mydrawerlayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerlist = (ListView) findViewById(R.id.left_drawer);
drawerlist.setAdapter(newArrayAdapter<String(MainActivity.this,android.R.layout.sim        ple_list_item_2,mplanetlist));
    ActionBar actionbar = getSupportActionBar();
    actionbar.show();
    actionbar.setHomeButtonEnabled(true);
    actionbar.setDisplayHomeAsUpEnabled(true);

drawer_toggle=newActionBarDrawerToggle(MainActivity.this,mydrawerlayout,R.drawable.        ic_drawer, R.string.drawer_open , R.string.drawer_close )
    {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle("drawer_open");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle("drawer_closse");
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

    mydrawerlayout.setDrawerListener(drawer_toggle);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater m = getSupportMenuInflater();
    m.inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    return super.onPrepareOptionsMenu(menu);
}

}

推荐答案

我刚刚得到了我的项目,因为我使用Maven这更是一个重大的痛苦这个运行。

I just got this running on my project, which was an even more major pain because I'm using Maven.

不要在你的项目的支持库,但替换ActionBarSherlock lib文件夹中,这是R7支持库,与最新的R13版本。还有人说,你需要包括在订单和出口私人图书馆为好,这是不是真的适合我,因为我使用Maven。

Don't include the support library in your project, but replace the support library in the ActionBarSherlock lib folder, which is r7, with the newest r13 version. Others have said that you need to include private libraries in the order and export as well, which was not true for me because I'm using Maven.

本教程是让ABS和DrawerLayout一起工作很有帮助。

这篇关于NavigationDrawer与ActionBarSherlok的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:20