Note that there are some explanatory texts on larger screens.

plurals
  1. POaction bar - positioning of action items
    text
    copied!<p>I'm having a go at doing an android 4+ layout for an application that remotely controls another device via wifi/bluetooth. And I'm trying to use the action bar as best it can be used. </p> <p>In this app's case, I want to have a picker that selects basic system mode of operation for the remote device. And to the right of it I want an "edit setup" button. so user can either just select a mode of operation, or edit the selected mode of operation. I want the edit button right next to the picker because it makes sense to group them. These two actions surface most of the features people will normally use in the app.</p> <p>I'm using the default example code for an android activity, as inserted in my project by the wizard "new>other>android activity" it has a picker already setup and working.</p> <p>The issue is, that the picker gets put to the far left of the action bar, and all other action items start from the right and move to the left. I can't seem to lock the position of the "edit" action item immediately to the right of the inserted picker. </p> <p>items in menu XML look like this:</p> <pre><code>&lt;item android:id="@+id/edit_configuration" android:title="Edit" android:orderInCategory="2" android:layout_gravity="left" android:showAsAction="always" /&gt; &lt;item android:id="@+id/menu_settings" android:title="@string/menu_settings" android:orderInCategory="100" android:showAsAction="never" /&gt; </code></pre> <p>The picker needs to be inserted using code in onCreate for the activity class.</p> <pre><code> // Set up the action bar. final ActionBar actionBar = getActionBar(); actionBar.setDisplayShowTitleEnabled(false); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); // Set up the dropdown list navigation in the action bar. actionBar.setListNavigationCallbacks( // Specify a SpinnerAdapter to populate the dropdown list. new ArrayAdapter( actionBar.getThemedContext(), android.R.layout.simple_list_item_1, android.R.id.text1, new String[]{ getString(R.string.title_section1), getString(R.string.title_section2), getString(R.string.title_section3), }), this); </code></pre> <p>I've tried the standard layoutGravity attribute in the menu XML, but while it causes no error, it also doesn't do anything I can see.</p> <p><img src="https://i.stack.imgur.com/Z2pqp.png" alt="screenshot"></p> <p>If anyone knows how I can attach my edit button to the immediate right of my picker, I'd be really pleased to hear about how it can be done.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload