Unable to use AndroidDrawer (sidebar like facebook

2019-03-06 10:07发布

问题:

I am trying to use this AndroidDrawer sidebar library. As per the instructions, following is my code in mainactivity. The code is crashing with application "has stopped - force close" message

public class MainActivity extends Activity {

Drawer mDrawer;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);     
    setContentView(R.layout.activity_main);     
    mDrawer = Drawer.createLeftDrawer(this, R.layout.drawer_content);
    mDrawer.init();     
    mDrawer.show();
}   
}

Below is my drawer_content.xml - very simple just a textview:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >


<TextView
    android:id="@+id/tv_drawer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:text="Textview in drawer ... "
    android:inputType="textPostalAddress" >

</TextView>

</LinearLayout>

The activity_main.xml is also a simple Textview only:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:text="asdsadd"
    android:inputType="textPostalAddress" >

</TextView>

</LinearLayout>

回答1:

First thing; there's no need of library for this.

There's a very simple implementation for this. Take a look at this tutorial:

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Also, take a look at this post: and see if you want something like this:

Swiping Tabs inside a Navigation Drawer Fragment

If you want the full code here, let me know.

Good Luck .. :)



回答2:

As @mike suggested Navigation drawer is the new design pattern from google. You should use this implementation.

Official docs are here :

Design pattern

Sample Code and Tutorial