0

I want to provide a image button in place of action bar and on clicking that I want to display list of options and again on clicking any particular option I want to pass Intent.

How can I achieve this?Does anybody know If so help me out.

Thank you...

Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49
user3350830
  • 89
  • 1
  • 14
  • did your mean about button in action bar is menu option? did you try `android:showAsAction="always"` for `menuItem`? – Shayan Pourvatan Apr 08 '14 at 10:59
  • I want to provide list of options on clicking on the action bar(say im using overflow icon)If i click on that I want to provide list of options on the top left corner on my screen.. – user3350830 Apr 08 '14 at 11:10

4 Answers4

0

Go through the following link it will help you

https://developer.android.com/training/basics/actionbar/adding-buttons.html

0

You can set a custom view on your action bar, here is the link

How to display custom view in ActionBar?

Community
  • 1
  • 1
Abdul Mohsin
  • 1,253
  • 1
  • 13
  • 24
0

It can be done in two ways
Options 1: Create an layout XML with your image button, and set that layout to action bar. For example: In you activity copy the following lines.

ActionBar actionBar = getSupportActionBar();

LayoutInflater inflator = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflator.inflate(R.layout.search, null);

actionBar.setCustomView(v);

Now display a PopUp menu when the user clicks a ImageButton.

Option 2: Instead of setting the view for the ActionBar , you can use sub-Menu's in the action bar. For this you need to create sub-Menu.

for example:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/file"
          android:icon="@drawable/ic_new_game"
          android:title="@string/file" >
        <!-- "file" submenu -->
        <menu>
            <item android:id="@+id/create_new"
                  android:title="@string/create_new" />
            <item android:id="@+id/open"
                  android:title="@string/open" />
        </menu>
    </item>
</menu>

 Set an icon for the main `MenuItem` so it looks like an `ImageButton`, when the user click the first MenuItem it displays the its sub-`Menu`
Kartheek
  • 7,104
  • 3
  • 30
  • 44
0
In order to display the imagebutton in Actionbar. First add an item in main.xml.Which is Under MENU Folder.
for ex:
main.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:id="@+id/stopwatch"
        android:orderInCategory="50"
        android:icon="@drawable/ic_action_alarms"
         android:showAsAction="always|withText"
        android:title="Stopwatch"/>

</menu>

then add the following code in your mainActivity.java

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch(item.getItemId())
        {
        case (R.id.stopwatch):
            Toast.makeText(getApplicationContext(), "Stopwatch", Toast.LENGTH_SHORT).show();
        Intent i=new Intent(getApplicationContext(), Stopwatch.class);
        startActivity(i);
        break;

        return super.onOptionsItemSelected(item);
    }

and Don't forget to create another java class as Stopwatch.java