gpt4 book ai didi

android - 在 Android 2.2 的 ActionBarSherlock 中用作自定义 View 时的微调器下拉样式

转载 作者:行者123 更新时间:2023-11-29 14:52:41 25 4
gpt4 key购买 nike

我正在使用 ActionBarSherlock。在我的应用程序中,我需要在操作栏中使用 2 个微调器,因此我使用列表导航 + 添加带有自定义 View 的第二个微调器。

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

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 上看起来像(作为下拉菜单)。但是自定义 View 中的微调器在微调器 View 单击时显示对话框而不是下拉菜单。

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

enter image description here

最佳答案

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

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

关于android - 在 Android 2.2 的 ActionBarSherlock 中用作自定义 View 时的微调器下拉样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13629788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com