【问题标题】:Unable to use AndroidDrawer (sidebar like facebook)无法使用 AndroidDrawer(侧边栏如 facebook)
【发布时间】:2014-03-16 00:36:12
【问题描述】:

我正在尝试使用this AndroidDrawer sidebar library. 根据说明,以下是我在 mainactivity 中的代码。代码因应用程序“已停止 - 强制关闭”消息而崩溃

公共类 MainActivity 扩展 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();
}   
}

下面是我的 drawer_content.xml - 非常简单,只是一个文本视图:

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

activity_main.xml 也只是一个简单的 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/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:text="asdsadd"
    android:inputType="textPostalAddress" >

</TextView>

</LinearLayout>

【问题讨论】:

    标签: android user-interface slidingdrawer


    【解决方案1】:

    第一件事;不需要图书馆。

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

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

    另外,看看这篇文章:看看你是否想要这样的东西:

    Swiping Tabs inside a Navigation Drawer Fragment

    如果您想要这里的完整代码,请告诉我。

    祝你好运.. :)

    【讨论】:

    • 谢谢。这正是我所需要的,不需要使用库,这样更好
    • 没问题..即使我像你现在一样从某个地方学到东西.. :)..祝你好运.. :)
    【解决方案2】:

    正如@mike 所建议的,导航抽屉是谷歌的新设计模式。您应该使用此实现。

    官方文档在这里:

    Design pattern

    Sample Code and Tutorial

    【讨论】:

    • 感谢您指出这是现在官方文档的一部分,没有注意到。 +1。
    猜你喜欢
    • 2020-07-02
    • 2020-07-07
    • 2021-02-04
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-17
    相关资源
    最近更新 更多