Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ActionBar Menupoint ( with 3 Dots)

I wanted to implement the ActionBar (Android 4.0) in a test App to see how it works etc.

My question: Almost every App for 4.0 have on the right corner of the ActionBar a "menuButton" with a Icon that shows 3 vertical Dots. (See: http://cdn.gottabemobile.com/wp-content/uploads/2011/12/ICS-Screen05.jpg)

How can I implement this on my App?

I tried to implement this "menuButton" with ah Spinneradapter.. but this one always displays after the App Name in the ActionBar.

Btw. Another question: I have a refresh button in my App.. how can i make the "Refresh-Icon" spin, whenever its clicked?

Here is my Code...

Thanks for the Help, and please excuse my programming skills... i am a newbie! :)

public class IVOAppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

    SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list,
        android.R.layout.simple_spinner_dropdown_item);

    actionBar.setListNavigationCallbacks(mSpinnerAdapter, null);

    setContentView(R.layout.main);
}


/** Create ActionBar */
public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menubar, menu);
    return true;
}

/** Handle clicks on ActionBar */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {

    case R.id.menu_refresh:
        Toast.makeText(this, "Fake Refreshing..", Toast.LENGTH_SHORT).show();
    /*final Intent i = new Intent(this, Help.class);
    startActivity(i);*/
    break;
    case R.id.menu_settings:
        Toast.makeText(this, "Settings", Toast.LENGTH_SHORT).show();
    /*final Intent ii = new Intent(this, Options.class);
    startActivity(ii);*/
    break;


} return false;}}

XML ActionBar

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >


<item android:id="@+id/menu_refresh"
    android:icon="@drawable/ic_popup_sync_1"
    android:showAsAction="always"/>

<item android:id="@+id/menu_settings" 
    android:icon="@drawable/ic_menu_preferences"
    android:showAsAction="always"/></menu>
like image 865
HardStyle Avatar asked Jan 16 '12 16:01

HardStyle


1 Answers

How can I implement this on my App?

Have an options menu, with items that are not hoisted into the action bar as toolbar buttons and the like. Since you elected to make your own two options menu items have android::showAsAction="always", they will be toolbar buttons, leaving you with nothing for the spillover menu.

Note that you will only see the three-dots button on devices that lack an off-screen MENU button.

like image 139
CommonsWare Avatar answered Oct 31 '22 10:10

CommonsWare