如何实现导航抽屉没有行动起来吧,但与主屏幕上的按钮打开导航画面? [英] how to implement navigation drawer without action bar but opens the navigation screen with a button on main screen?

查看:103
本文介绍了如何实现导航抽屉没有行动起来吧,但与主屏幕上的按钮打开导航画面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抽屉式导航应用程序,已登录屏幕上的left_drawer片段(见链接:<一href="http://stackoverflow.com/questions/20798136/how-to-show-a-activitylogin-screen-under-android-navigation-drawer">how显示一个活动(登录屏幕),在安卓导航抽屉),我想开使用一个按钮,主屏幕这个登录界面,也不想在导航抽屉的操作栏。任何一个可以请帮我这个?

navigation drawer app that have login screen on its left_drawer fragment (see link: how to show a activity(login screen) under android navigation drawer ), I want to open this login screen from the main screen using a button and also don't want the action bar on navigation drawer. Can any one please help me with this?

在此先感谢!

推荐答案

这是很简单的实际。比动作条更容易。我写的答案几乎最简单的布局

It's quite simple actually. Easier than with ActionBar. I'm writing the answer with almost simplest of layouts

让你的XML是这样的:

make your xml something like this:

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

<!-- This is how your main page will look, just 2 buttons -->

    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="100dp" >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:onClick="onLeft"
        android:text="left" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:onClick="onRight"
        android:text="right" />
    </RelativeLayout>

<!-- Left Drawrer -->

    <RelativeLayout
    android:id="@+id/whatYouWantInLeftDrawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start" >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/background_dark" />
    <!-- you can have many more widgets here like buttons or labels -->
    </RelativeLayout>

<!-- Right Drawrer -->

    <RelativeLayout
    android:id="@+id/whatYouWantInRightDrawer"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:layout_gravity="right" >

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_green_light" />
    <!-- you can have many more widgets here like buttons or labels -->
    </RelativeLayout>

</android.support.v4.widget.DrawerLayout>

然后,让您的活动是这样的:

Then make your activity something like this:

public class MainActivity extends Activity {

RelativeLayout leftRL;
RelativeLayout rightRL;
DrawerLayout drawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
//      I'm removing the ActionBar.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    leftRL = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
    rightRL = (RelativeLayout)findViewById(R.id.whatYouWantInRightDrawer);
    drawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
    }

    public  void onLeft(View view)
    {
    drawerLayout.openDrawer(leftRL);
    }

    public  void onRight(View view)
    {
    drawerLayout.openDrawer(rightRL);
    }
}

就是这样。希望它能帮助。

That's it. Hope it helps.

这篇关于如何实现导航抽屉没有行动起来吧,但与主屏幕上的按钮打开导航画面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆