无法使用AndroidDrawer(边栏如Facebook)AndroidDrawer、边栏如、Facebook

2023-09-03 23:14:26 作者:梦断情殇

我想使用这AndroidDrawer侧边栏库。的按照指令,下面是我的code在mainactivity。在code崩溃与应用已停止 - 强制关闭的消息。

公共类MainActivity延伸活动{

 抽屉mDrawer;
@覆盖
保护无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_main);
    mDrawer = Drawer.createLeftDrawer(这一点,R.layout.drawer_content);
    mDrawer.init();
    mDrawer.show();
}
}
 

下面是我的 drawer_content.xml - 很简单,只是一个TextView:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>


<的TextView
    机器人:ID =@ + ID / tv_drawer
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:EMS =10
    机器人:文本=TextView的抽屉......
    机器人:inputType =textPostalAddress>

< / TextView的>

< / LinearLayout中>
 

在 activity_main.xml 也是一个简单的TextView只:

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直>

<的TextView
    机器人:ID =@ + ID / editText1
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:EMS =10
    机器人:文本=asdsadd
    机器人:inputType =textPostalAddress>

< / TextView的>

< / LinearLayout中>
 
最火的Android开源项目 第01期

解决方案

第一件事;没有必要库这一点。

有一个非常简单的实现了这一点。看看这个教程:

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

此外,一起来看看这篇文章:看看,如果你想是这样的:

Swiping内部的导航抽屉片段标签

如果你想在这里充分code,让我知道。

好运..:)

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>

解决方案

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 .. :)