Skip to content Skip to sidebar Skip to footer

How To Implement Navigation Drawer Without Action Bar But Opens The Navigation Screen With A Button On Main Screen?

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 log

Solution 1:

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

make your xml something like this:

<android.support.v4.widget.DrawerLayoutxmlns: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 --><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="100dp" ><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentLeft="true"android:onClick="onLeft"android:text="left" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentRight="true"android:onClick="onRight"android:text="right" /></RelativeLayout><!-- Left Drawrer --><RelativeLayoutandroid:id="@+id/whatYouWantInLeftDrawer"android:layout_width="240dp"android:layout_height="match_parent"android:layout_gravity="start" ><ListViewandroid: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 --><RelativeLayoutandroid:id="@+id/whatYouWantInRightDrawer"android:layout_width="200dp"android:layout_height="wrap_content"android:layout_gravity="right" ><ListViewandroid: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:

publicclassMainActivityextendsActivity {

RelativeLayout leftRL;
RelativeLayout rightRL;
DrawerLayout drawerLayout;

    @OverrideprotectedvoidonCreate(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);
    }

    publicvoidonLeft(View view)
    {
    drawerLayout.openDrawer(leftRL);
    }

    publicvoidonRight(View view)
    {
    drawerLayout.openDrawer(rightRL);
    }
}

That's it. Hope it helps.

Solution 2:

You can use a Navigation Drawer. Very easy to implement and very professional looking. Instead of putting a listview in your Navigation Drawer just create another layout and inflate the layout when your Navigation Drawer is active. You can view information about a Navigation Drawer here.

Your going to find many ways to have a slide out drawer. But your problem is going to be creating a custom layout and inflating it inside the Navigation Drawer.

Best of luck to you!

Post a Comment for "How To Implement Navigation Drawer Without Action Bar But Opens The Navigation Screen With A Button On Main Screen?"