1

I have been looking online for a while, and there are very little tutorials on how to do this. Even the google docs have very vague info on how to put this stuff up there! I am sure its subtle, but I can't understand the terminology because I am still fairly new to Android. I would like to be able to get the Action Overflow icon to the right side of the ActionBar. Putting the view control was pretty understandable using the docs and example code when creating a project, but it does not have one for the Action Overflow. Thanks in advance!

Edit: I should probably elaborate. I would like the menus to default being under the action overflow. I found an eye opener answer to a similar question, but it only tells you how to put the menus at the top. How can I force them to go under the list? Is it even possible to force that? Thanks!

4

1 に答える 1

4

API-11 を使えば問題ありません。低い場合は、このトピックに招待しています: ICS のように android 2.x でドロップダウン メニューを作成する最良の方法

API-11 以降の場合は、次のことを行う必要があります。

  1. 次のようなメニュー xml を作成します。

         <?xml version="1.0" encoding="utf-8"?>
         <menu xmlns:android="http://schemas.android.com/apk/res/android" >
    
            <item
                android:id="@+id/item_refresh"
                android:icon="@drawable/ic_menu_refresh"
                android:title="Refresh"
                android:showAsAction="ifRoom|withText" />
    
            <item
                android:id="@+id/item_save"
                android:icon="@drawable/ic_menu_save"
                android:title="Save"
                android:showAsAction="ifRoom|withText" />
        </menu>
    

そして、次のようなコードを作成します:

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // gets the activity's default ActionBar
    ActionBar actionBar = getActionBar();
    actionBar.show();
    actionBar.setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu); //inflate our menu
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch(item.getItemId()) {
    case R.id.item_refresh:
        //click on refresh item
        break;
    case R.id.item_save:
        //click on save item
        break;
    }
    return true;
}

幸運を!

于 2012-07-23T05:04:44.847 に答える