Unable to use AndroidDrawer (sidebar like facebook)

时间秒杀一切 提交于 2019-12-02 17:15:01

问题


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



来源:https://stackoverflow.com/questions/22431553/unable-to-use-androiddrawer-sidebar-like-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!