Helpme
Helpme

Reputation: 59

How to create ActionBar With Button Items Using Android?

I need to create ActionBar with left side button item looks like below mentioned Image. I tried by using huge of codes, but still I didnt get anything. Please help me to create android ActionBar with button.

I need to create like below Image

NOTE: I don't have sample code, Moreover It's not proper because I am new developer for android.

Upvotes: 0

Views: 56

Answers (1)

Mrad Mrad
Mrad Mrad

Reputation: 542

To Add Action Buttons add this in your activity

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

 //and this to handle actions


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

and this in your main.xml under menu directory

<item android:id="@+id/action_settings" 
        android:title="@string/action_settings"
        android:icon="@drawable/icon"
        android:orderInCategory="100" 
        app:showAsAction="always" />

To get the icon to the left see this

Upvotes: 1

Related Questions