从操作项自定义下拉(actionbarsherlock) [英] Custom drop-down from action item (actionbarsherlock)

查看:134
本文介绍了从操作项自定义下拉(actionbarsherlock)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个自定义下拉连接到一个操作项菜单。我设法做同样的事,主页图标,但似乎它的工作与其他行动项目完全不同。

我知道这个问题,并回答:如何在操作栏添加下拉项 我的问题是,我想完全自定义(我使用自定义的字体,还需要图标),这样子菜单是不够的,我想。并附加一个自定义的微调 actionLayout 看上去一点也不像降下来了。

有关的主页图标,它看起来是这样的:

  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ArrayList的<的NavItem>数据=新的ArrayList<的NavItem>();
    data.add(...);
    data.add(...);
    ActionBarNavAdapter适配器=新ActionBarNavAdapter(...);
    actionBar.setListNavigationCallbacks(适配器,新OnNavigationListener(){...});
 

和我可以添加自己的设计,它在不牺牲下拉的事情。 如何与其他行动项目办呢?

编辑: 我知道使用活动 NAVIGATION_MODE_LIST 使用微调(ListNavigationCallbacks使用 SpinnerAdapter ),但它看起来更好,我不知道从哪里得到所有这些风格(如果它只是),使它看起来像。我的意思是:

- >如何 NAVIGATION_MODE_LIST 的外观:它包裹的名单,这是附着在主页图标。 - >如何自定义微调 actionLayout 的外观:它的屏幕宽度相匹配有一些额外的黑暗背景下,替换操作项的图标(这是很容易改变)及以上的所有,变暗屏幕的其余部分。它看起来很像一个自定义列表,而不是一个下拉菜单中选择一个AlertDialog。

code:

  @覆盖
公共布尔prepareOptionsMenu(功能菜单)在{
    菜单项sortItem = menu.findItem(R.id.sort);
    微调微调=新的微调(本);

    //这是同一个适配器,因为我不想花时间创建一个新的
    // ActionBarNavAdapter扩展,当然SpinnerAdapter
    ArrayList的<的NavItem>数据=新的ArrayList<的NavItem>();
    data.add(...);
    data.add(...);
    ActionBarNavAdapter适配器=新ActionBarNavAdapter(...);
    spinner.setAdapter(适配器);
    sortItem.setActionView(微调);
    返回true;
}
 

解决方案

尝试更换:

 微调微调=新的微调(本);
 

 微调微调=新的微调(getActionBar()getThemedContext());
 

这将使用上下文主题相匹配的操作栏,并且应该帮助。

I need a custom drop-down menu attached to an action item. I managed to do the same thing for the home icon, but it seems that it's done totally different with other action items.

I know this question and answer: How to add a Dropdown item on the action bar My problem is that I want to fully customize it (I use custom fonts, will also need icons), so a submenu wouldn't suffice, I suppose. And attaching a custom Spinner as an actionLayout looks nothing like drop down.

For the home icon it looks like this:

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    ArrayList<NavItem> data = new ArrayList<NavItem>();
    data.add(...);
    data.add(...);
    ActionBarNavAdapter adapter = new ActionBarNavAdapter(...);
    actionBar.setListNavigationCallbacks(adapter, new OnNavigationListener() {...});

And I could add my own design to it without sacrificing the "drop-down" thing. How to do it with other action items?

EDIT: I know that activity using NAVIGATION_MODE_LIST uses Spinner (ListNavigationCallbacks uses a SpinnerAdapter) but it looks better and I don't know where to get all those styles (if it's just that) to make it look like that. I mean:

Good -> How NAVIGATION_MODE_LIST looks: it's wrapping the list, it's attached under the home icon. Bad -> How a custom Spinner as an actionLayout looks: it matches the screen width with some additional dark background, replaces the action item icon (this is easy to change) and above all, darkens the rest of the screen. It look rather like an AlertDialog with a custom list, not a drop-down menu.

Code:

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem sortItem = menu.findItem(R.id.sort);
    Spinner spinner = new Spinner(this);

    //this is the same adapter because I didn't want to spend time creating a new one
    //ActionBarNavAdapter extends SpinnerAdapter of course
    ArrayList<NavItem> data = new ArrayList<NavItem>();
    data.add(...);
    data.add(...);
    ActionBarNavAdapter adapter = new ActionBarNavAdapter(...);
    spinner.setAdapter(adapter);
    sortItem.setActionView(spinner);
    return true;
}

解决方案

Try replacing:

Spinner spinner = new Spinner(this);

with:

Spinner spinner = new Spinner(getActionBar().getThemedContext());

This will use a Context themed to match the action bar, and should help.

这篇关于从操作项自定义下拉(actionbarsherlock)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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