Android ActionBar Menupoint (with 3 points)

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

My question is: almost all applications for 4.0 have in the right corner of the ActionBar a "menuButton" with an icon that shows 3 vertical dots. (See: http://cdn.gottabemobile.com/wp-content/uploads/2011/12/ICS-Screen05.jpg )

How can I implement this in my application?

I tried to implement this "menuButton" using ah Spinneradapter .. but this is always displayed after the application name in the ActionBar.

Btw. Another question: I have an update button in my application .. how can I spin the "Refresh-Icon" every time I click?

Here is my code ...

Thanks for the help, and please excuse my programming skills ... I'm new! :)

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> 
+6
source share
1 answer

How can I implement this in my application?

You have an options menu with elements that do not go up to the action bar in the form of buttons on the toolbar and the like. Since you selected your own menu items, android::showAsAction="always" , they will become toolbar buttons and you will not get anything for the overflow menu.

Please note that you will only see the three dots button on devices that do not have a MENU button on the screen.

+7
source

Source: https://habr.com/ru/post/906133/


All Articles