我正在尝试更改操作栏中微调器的文本颜色。我想更改操作栏上显示的文本颜色,而不更改下拉项目的颜色
这是一张描述我的意思的图片
答案 0 :(得分:0)
如果将简单数组适配器设置为spinner
ArrayAdapter<String> customeAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, listview_array);
actSpinner.setAdapter(customeAdapter);
然后你可以改变那样的文字颜色
actSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
CheckedTextView textView= (CheckedTextView)arg1;
textView.setTextColor(Color.GREEN);
System.err.println("arg2="+ arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
或者您可以使用微调器自定义操作栏
getActionBar().setDisplayShowCustomEnabled(true);
View view = getLayoutInflater().inflate(R.layout.spineer_view_layout, null);
Spinner actSpinner = (Spinner) view.findViewById(R.id.spinner_action_bar);
getActionBar().setCustomView(view);
MyCustomeAdapter customeAdapter = new MyCustomeAdapter(this, listview_array);
actSpinner.setAdapter(customeAdapter);
actSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
LinearLayout linearLayout = (LinearLayout )arg1;
TextView textView =(TextView) linearLayout.getChildAt(0);
textView .setTextColor(Color.GREEN);
System.err.println("arg2="+ arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spinner_action_bar
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner_action_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这是Custome Adpater的getView
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
LayoutInflater layoutInflater = (LayoutInflater) activity
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = layoutInflater.inflate(
R.layout.adapter_offer_item_layout, null);
holder.descritpionTextView = (TextView) convertView.findViewById(R.id.value);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.descritpionTextView.setText(listview_array[position]);
return convertView;
}
private class ViewHolder {
TextView descritpionTextView;
}
adapter_offer_item_layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/value"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>