添加微调器来操作菜单栏 [英] Add Spinner To Action Menu Bar

查看:140
本文介绍了添加微调器来操作菜单栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个例子,如何添加微调项目与项目的数组到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));

这篇关于添加微调器来操作菜单栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆