0

Please give me an advise .How to add the menu icon(that three lines symbol) for an already created project. Also I wanna add the menu icon only for some layouts.
Please help would be very thankful..I mean this symbol

SamithaP
  • 90
  • 1
  • 1
  • 13
  • Possible duplicate of [How to add "menu" indicator next to Action Bar's app icon?](http://stackoverflow.com/questions/19724567/how-to-add-menu-indicator-next-to-action-bars-app-icon) – Harsha W Apr 18 '17 at 04:56
  • Post your java and xml codes what you have tried so far? – Ferdous Ahamed Apr 18 '17 at 06:40

4 Answers4

4

To create menu in your application first create on Folder inside res directory named menu.

Then in menu create one file main_menu.xml

Add below code into main_menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:title="Item1" android:id="@+id/item1"></item>
    <item android:title="Item2" android:id="@+id/item2"></item>
</menu>

Here title which show in your menu.

To add menu in any activity put below code in your activity file.

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the main_menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        switch(item.getItemId()) {
            case R.id.item1:
               //your action
                break;
            case R.id.item2:
                //your action
                break;
            default:
                return super.onOptionsItemSelected(item);
        }

        return true;
    }
Jaimin Prajapati
  • 341
  • 5
  • 14
  • Brother Thanks for your reply.. Is this the hamburger Icon.? I meant the hamburger Icon. – SamithaP Apr 18 '17 at 05:21
  • No hamburger is for navigation drawer for menu it is three vertical dots. – Jaimin Prajapati Apr 18 '17 at 05:23
  • Yes.. that's what I want. I have already created my project and I wanna add the hamburger icon to one layout..it's not the first layout. How can I do it? Thanks – SamithaP Apr 18 '17 at 05:27
  • You want to create menu or navigation drawer? First clear it. And for add menu in existing project to add the code in Activity file which i mention above – Jaimin Prajapati Apr 18 '17 at 05:28
  • I wanna create a navigation drawer for one layout.. it should open when I click the hamburger Icon. :) I think it's clear now..Please help.and appreciate your help! – SamithaP Apr 18 '17 at 05:37
  • Android Studio automatically creates a NavigationDrawer Activity for you. Right-click and highlight the option to create a new activity. This will display the various types of activities you can use. Select NavigationDrawer Activity and the mainActivity, navDrawerFragment, activity_main.xml, and navdrawer.xml files will be created for you. – Jaimin Prajapati Apr 18 '17 at 05:41
  • mmm yes.. but it opens new activity.. but I want to add this for already created activity. anyway I can do it since its just a single page know. thanks a lot for your help.. – SamithaP Apr 18 '17 at 05:59
  • Hello brother, I need another help.I wanna know that can I use firebase as a database for every database purposes. I mean can I use firebase instead of sqlite? – SamithaP Apr 24 '17 at 04:09
  • Sqlite database is local database which is specific to particular device only. Firebase Realtime Database is nosql database which can access from any device and you can use it for any purpose. If you want to use RDBMS then you need to create one web service to access those database because android directly does not support database like mysql and oracle. – Jaimin Prajapati Apr 24 '17 at 19:19
  • Hello brother. Sorry if I'm disturbing.I wanna add data into firebase database.then I wanna retrieve a summary of the added data that will show inside a button. when the button clicked the entire data should show. If you get my idea. please give me some advise. – SamithaP May 03 '17 at 12:56
0

// enables the activity icon as a 'home' button.

 getActionBar().setHomeButtonEnabled(true);
bhaskar kurzekar
  • 238
  • 2
  • 14
0

You can use hamburger icon as in toolbar.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.wolfmatrix.dummy.MainActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbarId"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    android:background="@color/colorPrimary">

    <TextView
        android:id="@+id/toolbarTextId"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="left"
        android:textColor="@android:color/white"
        android:textSize="14sp" />
</android.support.v7.widget.Toolbar>

<ImageButton
    android:id="@+id/backButtonIcon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    android:gravity="left"
    android:padding="10dp"
    app:srcCompat="@drawable/ic_hamburger_icon_black_24dp" />

</RelativeLayout>
Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
0

If you are using Toolbar in your layout XML then you can change Home icon as below:

Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.hamburger_icon);
Ferdous Ahamed
  • 21,438
  • 5
  • 52
  • 61