在Android 2.2上的ActionBarSherlock中用作自定义视图时的Spinner下拉样式

时间:2012-11-29 16:05:13

标签: android android-actionbar actionbarsherlock android-spinner

我正在使用ActionBarSherlock。在我的应用程序中,我需要2个旋转器在操作栏中,所以我使用列表导航+添加第二个微调器与自定义视图。

我使用以下代码将微调器添加到自定义视图:

ActionBar bar = getSupportActionBar();

// FALLBACK: Use native actionbar dropdown style for 11+ API. Or use ActionBarSherlock style.
int dropDownStyle = (VERSION.SDK_INT < 11) ? R.attr.actionDropDownStyle : android.R.attr.actionDropDownStyle;           

MyAdapter someAdapter = new MyAdapter(this, list);          

Spinner mySpinner = new Spinner(this, null, dropDownStyle);                    
mySpinner.setAdapter(someAdapter);        
mySpinner.setOnItemSelectedListener(this);

bar.setCustomView(mySpinner);
bar.setDisplayShowCustomEnabled(true);

在Android 4.0.3上,一切都运行良好。

Android 2.2行为

列表导航微调器在Android 4.0.4上看起来像(下拉列表)。但是自定义视图中的微调器会在微调器视图上显示对话框而不是下拉列表。

所以我需要在Android 2.2上自定义视图中显示Spinner作为下拉列表,就像在Android 4.0.4上一样。

enter image description here

1 个答案:

答案 0 :(得分:6)

ActionBarSherlock使用自定义微调控件IcsSpinner,它提供下拉功能。虽然这在internal包中确实存在,但它是一个公共类,因此您可以切换代码以使用它。这应该为您提供列表导航控件使用的下拉列表的精确镜像。

但是,请记住,此控件并非设计为在任何地方使用,而是作为内置列表导航使用,因此可能缺少您想要的功能或功能。

相关问题