3

我正在使用如下所示的导航抽屉:Android 示例。目前,Actionbar 是静态的,抽屉打开/关闭时它不会移动(只是它的标题发生了变化)。如何应用此效果:

图片

我希望整个 ActionBar 与滑动片段一起移动。并且 ActionBar 上的 Name 和 Buttons 保持原样。请告诉我您需要查看哪些代码。

另外,问题 2:

当您使用时,DrawerLayout您在 xml 中包含 FrameLayout(用于 content_frame)和 ListView(您在其中添加导航设置......在该抽屉中,您可以修改布局,以便您不仅可以添加 ListView,还可以添加其他视图? 在 ListView 的顶部或底部?像这样的东西:

在此处输入图像描述

我想添加未超链接的 ImageView(不是超链接,只是图像)和 Additional TextViews(用于说明)。

4

4 回答 4

9

考虑使用SlidingMenu来自GitHub. 它非常灵活,你可以用它做任何事情。您只需调用以下命令即可滑动操作栏:

setSlidingActionBarEnabled(true);

https://github.com/jfeinstein10/SlidingMenu

于 2013-08-31T19:34:01.000 回答
2

第二点:当然可以。NavigationDrawer 不仅限于使用 ListView。只需使用像 LinearLayout 这样的 ViewGroup 作为 DrawerLayout 的第二个子项,然后放入您想要的任何视图。但请记住在 LinearLayout 的规范中添加这一行:

<LinearLayout
     ...
     android:layout_gravity="start"
     ...>

     <TextView..../>
     <ImageView...../>
<LinearLayout/>
于 2013-08-31T19:30:15.027 回答
2

我认为您可以使用这种布局来实现抽屉列表视图顶部的某些视图..

<!-- The main content view -->

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>
<!-- The navigation drawer -->

<RelativeLayout
    android:id="@+id/drawerLeft"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start"
    android:background="#191919" >

    <EditText
        android:id="@+id/edit_Search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FC3A3B"
        android:hint="  Search"
        android:padding="10dp"
        android:textColor="#ffffff"
        android:textColorHint="#ffffff" >

        <requestFocus />
    </EditText>

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/edit_Search"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="20dp"
        android:src="@drawable/icon_small_search" />

    <ListView
        android:id="@+id/drawer_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/edit_Search"
        android:background="#191919"
        android:choiceMode="singleChoice"
        android:divider="#000000"
        android:dividerHeight="1dp" >
    </ListView>
</RelativeLayout>

于 2014-01-22T04:52:56.497 回答
1

我想这就是你要找的。这是您所引用示例的示例源代码中的代码。

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
    mDrawerLayout, /* DrawerLayout object */
    R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open, /* "open drawer" description for accessibility */
    R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to
                                        // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
于 2013-08-31T15:59:43.893 回答