我正在使用 ActionBarSherlock 并想更改操作栏导航微调器中文本的颜色。有人可以提供执行此操作所需的 xml 示例吗?
谢谢
我正在使用 ActionBarSherlock 并想更改操作栏导航微调器中文本的颜色。有人可以提供执行此操作所需的 xml 示例吗?
谢谢
我刚刚结束了使用带有白色文本的文本视图的自定义微调器项目布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:paddingLeft="10dp"
android:textSize="18sp"
android:textColor="#FFFFFF" />
尝试这个
<style name="YourTheme" parent="YourParentTheme">
<item name="android:spinnerDropDownItemStyle">@style/YourCustomDropDownItemStyle</item>
</style>
现在,为您的样式设置 textappearance:
<style name="YourCustomDropDownItemStyle" parent="Widget.Holo.DropDownItem.Spinner">
<item name="android:textAppearance">@style/YourCustomDropDownItemTextStyle</item>
</style>
在您的自定义文本外观中,您可以设置文本详细信息:
<style name="YourCustomDropDownItemTextStyle" parent="Widget">
<item name="android:textColor">@color/white</item>
<!-- Here you can set the color and other text attributes -->
</style>
只是为了添加答案,我需要两个资源,因为操作栏需要白色,但下拉需要标准黑色
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
getActivity().getActionBar().getThemedContext(),
R.layout.spinner_custom_item, names);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
检查这个。
在 res/values/themes.xml 下
<style name="MY_THEME" parent="android:Theme">
<item name="android:spinnerStyle">@style/SpinnerSelector</item>
</style>
在 res/values/styles.xml 下
<resources>
<style name="SpinnerSelector">
<item name="android:background">@drawable/spinner_selector</item>
<item name="android:clickable">true</item>
</style>
在 res/drawable/spinner_selector.xml 下
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/btn_dropdown_normal" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/btn_dropdown_disabled" android:text="#FFFFFF"/>
<item android:state_pressed="true" android:drawable="@drawable/btn_dropdown_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_dropdown_selected" />
<item android:state_enabled="true" android:drawable="@drawable/btn_dropdown_normal" />
<item android:state_focused="true" android:drawable="@drawable/btn_dropdown_disabled" android:text="#FFFFFF"/>
<item android:drawable="@drawable/btn_dropdown_disabled" />
</selector>
在活动中,
Spinner mSpnrTranscationType = new Spinner(this);
ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(
this, R.array.transaction_type_list,
R.layout.spinner_item_white);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mSpnrTranscationType.setAdapter(adapter2);
在 res/layout/spinner_item_white.xml 下,
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:textColor="@color/white" />