我有一个HashMap<String,String>静态方法,将此地图返回给Activity.
方法如下所示:
public static HashMap<String, String> getAll() {
HashMap<String, String> map = new HashMap<String,String>();
map.put("ab", "value1");
map.put("bc", "value2");
map.put("de", "value3");
return map;
}
Run Code Online (Sandbox Code Playgroud)
我想用旋转器来使用那个地图.所以活动看起来像这样:
List list = new ArrayList<String>();
HashMap<String, String> map = Constants.getAll();
for (String key : map.keySet()) {
list.add(Constants.getAll().get(key).toString());
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinTest = (Spinner)findViewById(R.id.spinTest);
spinTest.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
urlDebug.setText(list.get(arg2).toString());
}
public void onNothingSelected(AdapterView<?> arg0) {
}
}); …Run Code Online (Sandbox Code Playgroud) 所以我有一个微调器,我成功地改变了所选项目的颜色,但是我无法在下拉菜单中更改项目的颜色
这是我的spinner_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:textColor="#33CCFF"
/>
Run Code Online (Sandbox Code Playgroud)
这是我的styles.xml
<resources>
<style name="AppTheme" parent="android:Theme.Light" >
<item name="android:spinnerDropDownItemStyle">@style/SpinnerItem.DropDownItem.Color</item>
<item name="android:spinnerItemStyle">@style/SpinnerItem</item>
</style>
<style name="SpinnerItem.DropDownItem.Color" parent="@android:style/Widget.DropDownItem.Spinner">
<item name="android:textColor">#4FBDE8</item>
</style>
<style name="SpinnerItem" parent="@android:style/Widget.TextView.SpinnerItem">
<item name="android:textColor">#4FBDE8</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
有没有XML方法可以做到?
如何删除微调器中的分隔线?
例如,如何删除/控制这些白色分隔线?

PS这是行布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/black">
<TextView
android:id="@+id/catalog_spinner_item_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="11dp"
android:text="@string/CatalogSpinnerItemRowDefaultText"
android:textSize="18sp"
android:gravity="center_vertical"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我无法使用下面的代码更改微调器的文本大小或颜色:
<Spinner
android:id="@+id/spinner1"
style="@style/submitspinner"
android:layout_weight="2"
android:entries="@array/a_code"
android:prompt="@string/p_code" />
Run Code Online (Sandbox Code Playgroud)
样式:
<style name="submitspinner" parent="@android:TextAppearance.Widget.TextView.SpinnerItem">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_margin">10sp</item>
<item name="android:textColor">@android:color/holo_blue_dark</item>
<item name="android:textSize">@dimen/pt</item>
</style>
Run Code Online (Sandbox Code Playgroud)
它看起来一样,如何增加文本大小并改变微调器的颜色?
我正在寻找一个示例如何将带有项目数组的微调器项添加到Android菜单选项.
我看了很多例子,但没有任何简单的例子我可以罚款.我想在屏幕顶部的Action Bar中添加一个项目.
我有这个错误setOnItemSelectedListener:
AdapterView类型中的方法setOnItemSelectedListener(AdapterView.OnItemSelectedListener)不适用于参数(FragmentMain)"
片段类:
public class FragmentMain extends Fragment {
private Spinner countriesSpinner;
private Activity rootView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){
View rootView =inflater.inflate(R.layout.activity_main, container, false);
return rootView;
}
@Override
public void onStart() {
super.onStart();
addItemsOnSpinner();
}
public void addItemsOnSpinner() {
countriesSpinner = (Spinner) rootView.findViewById(R.id.team_list_spinner);
countriesSpinner.setOnItemSelectedListener(new CustomOnItemSelectedListener ()) ;
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.team_list, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
countriesSpinner.setAdapter(adapter);
countriesSpinner.setOnItemSelectedListener(this);
}
public class CustomOnItemSelectedListener extends Activity implements
OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, …Run Code Online (Sandbox Code Playgroud) Android Spinner GUI组件是具有自动完成功能的典型下拉列表.
带有数据列表的HTML5选择也是如此,但不幸的是,Android中带有datalist的HTML5 不是.
当然Android直到明年才会支持datalist(他们声称).更重要的是,任何HTML选择都是平板电脑上的黑客工作.在电话上,没关系.在平板电脑上,选择不是下拉菜单,而是在屏幕底部向上滑动一个简短列表.该列表具有单选按钮和完成按钮.它是一个奇怪的小UI组件,它放入屏幕而不是显示下拉列表.有没有办法告诉Android做正确的事情?要像在桌面上的Web浏览器中那样对待它吗?
我已经使用了jQuery UI droplist,它在平板电脑上没问题,但在手机上却很糟糕.在手机上键盘出现并阻挡显示屏.有没有办法告诉Android做正确的事情?要不显示此特定html输入元素的键盘?
我可以告诉Android:
我为Fragment创建了一个微调器,用从HTTP标注中检索的数据填充它.首次创建Fragment时,我使用其选择选项填充微调器,设置其setOnItemSelectedListener并在onCreateView()中设置其初始选择.
stateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
if (spinnerPosition != position)
{
spinnerPosition = position;
TextView stateSelected = (TextView) view;
String stateSelectedStr = stateSelected.getText().toString();
LinearLayout ballotsDisplay = (LinearLayout) getActivity().findViewById(R.id.ballotsDisplay);
ballotsDisplay.removeAllViews();
Map<String, String> calloutParams = new HashMap<String, String>();
calloutParams.put("state", stateSelectedStr);
// Create and execute AsyncTask to retrieve ballots
new RetrieveBallots().execute(calloutParams);
}
}
public void onNothingSelected(AdapterView<?> parent) {
return;
}
});
// Set default selection for spinner
int defaultState = adapter.getPosition(userState);
if (defaultState == …Run Code Online (Sandbox Code Playgroud) 这是我的微调器布局,
<Spinner
android:layout_marginLeft="20dp"
android:background="@android:drawable/btn_dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinnerQuality"
android:layout_gravity="center_horizontal"
/>
Run Code Online (Sandbox Code Playgroud)
和微调项目布局,
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingTop="10dp"
android:paddingLeft="10dp"/>
Run Code Online (Sandbox Code Playgroud)
并显示微调器是,

但我想让微调器和下拉项目背景透明.我怎么会这样?
android-spinner ×10
android ×9
android-menu ×1
dropdown ×1
hashmap ×1
html5 ×1
select ×1
separator ×1
styles ×1
textcolor ×1
whitespace ×1