添加微调器来操作菜单栏菜单栏、操作

2023-09-05 07:29:07 作者:妄饮晩冬酒

我要寻找一个例子,如何添加微调项目与项目的数组到Android菜单选项。

I am looking for a example how to add spinner Item with an array of items to Android Menu Options .

我看很多例子,但没有任何简单的例子,我可以罚款。我想一个项目到操作栏上方的屏幕。

I look many examples but there is not any simple example i can fine .I want to add an item to Action Bar on Top of screen.

推荐答案

微调在正确的操作栏福尔摩斯与IcsLinearLayout

private String[] mLocations;

ActionBar actionBar = getSupportActionBar();
    final Context themedContext = actionBar.getThemedContext();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(themedContext,
            R.layout.sherlock_spinner_item, mLocations);
    adapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);

    // create ICS spinner
    spinner = new IcsSpinner(this, null, R.attr.actionDropDownStyle);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(IcsAdapterView<?> parent, View view,
                int position, long id) {

        }

        @Override
        public void onNothingSelected(IcsAdapterView<?> parent) {
        }
    });

    // configure custom view
    IcsLinearLayout listNavLayout = (IcsLinearLayout) getLayoutInflater()
            .inflate(R.layout.abs__action_bar_tab_bar_view, null);
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER;
    listNavLayout.addView(spinner, params);
    listNavLayout.setGravity(Gravity.RIGHT); //align the spinner to the right

    // configure action bar
    actionBar.setCustomView(listNavLayout, new ActionBar.LayoutParams(
            Gravity.RIGHT));