我需要在用户输入布局时显示“drawerlayout”

时间:2014-01-10 14:32:35

标签: android android-layout drawerlayout

我想要的是显示隐藏在左侧的栏,当用户输入布局时,想法是你知道有那个栏而不必在动作栏上放置一个表示其存在的图标< / p>

1 个答案:

答案 0 :(得分:1)

如果您想在第一次创建活动时打开导航栏,您可以执行以下操作:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer_activity);

    drawer = (ListView) findViewById(R.id.left_drawer); // the drawer itself (ListView for example)
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // the drawer layout itself

    drawerLayout.openDrawer(drawer);
}

您的xml可能如下所示:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/background_activity_color">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/fragmentFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    <!-- The navigation drawer -->
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="250dp"
        android:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>