【发布时间】:2015-06-19 16:07:50
【问题描述】:
我在设置微调器样式时遇到了几个问题
- 我需要更改微调器的可绘制对象(选定视图) 当用户打开下拉列表时(我尝试了几个选择器 具有不同的状态,但没有任何工作正常)
- 我无法更改下拉列表中项目的文本颜色(我可以更改 颜色,但我需要为所选值使用不同的颜色)你可以看到更多 详情见下方链接。
- 我无法从下拉列表中删除分隔线。
我不想使用带有按钮和列表的自定义布局来模拟微调器的功能(但如果没有解决方案我会这样做)。
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:background">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/white</item>
<item name="android:colorBackground">@android:color/white</item>
<item name="android:dropDownSpinnerStyle">@style/SpinnerTheme</item>
</style>
<style name="SpinnerAppTheme" parent="android:Widget.Holo.Light.Spinner">
<item name="android:background">@drawable/spinner_background_holo_light</item>
<item name="android:dropDownSelector">@drawable/list_selector_holo_light</item>
<item name="android:dropDownListViewStyle">@style/mySpinnerStyle</item>
</style>
<style name="mySpinnerStyle" parent="android:Widget.ListView.DropDown">
<item name="android:divider">@null</item>
<item name="android:dividerHeight">0px</item>
</style>
<style name="Theme_Dialog_Translucent" parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:background">@android:color/white</item>
<item name="android:windowTitleStyle">@style/dialog_title_style</item>
</style>
<style name="Theme_Dialog_Measurment_Data_Dialog" parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:background">@color/general_background_color</item>
<item name="android:windowTitleStyle">@style/dialog_title_style</item>
</style>
<style name="dialog_title_style" parent="android:Widget.TextView">
<item name="android:textColor">@android:color/black</item>
</style>
<Spinner
android:id="@+id/res_spinner"
android:layout_width="0dp"
android:layout_height="30dp"
android:layout_weight="60"
android:background="@drawable/ref_spinner_selector"
android:dropDownVerticalOffset="1dp"
android:dropDownWidth="60dp"
android:gravity="center"
android:popupBackground="@null"
android:spinnerMode="dropdown"/>
how the spinner needs to be look like
how the spinner looks like now
谢谢
更新: 如果有人在自定义微调器时遇到问题
我设法使用 ListPopupWindow 解决了所有问题
private void initPopup()
{
_lp = new ListPopupWindow(getActivity());
_lp.setAnchorView(_resTitle);
ColorDrawable cd = new ColorDrawable(getResources().getColor(android.R.color.transparent));
_lp.setBackgroundDrawable(cd);
_lp.setOnDismissListener(new OnDismissListener()
{
@Override
public void onDismiss()
{
_resTitle.setSelected(false);
}
});
_listPopupAdapter = new DataSetListAdapter(getActivity(), _resData);
_lp.setAdapter(_listPopupAdapter);
}
点击
案例R.id.res_title:
if (!_lp.isShowing())
{
_resTitle.setSelected(true);
_lp.setOnItemClickListener(this);
_lp.show();
_lp.getListView().setDivider(null);
_lp.getListView().setDividerHeight(0);
}
else
{
_resTitle.setSelected(false);
_lp.dismiss();
}
break;
【问题讨论】: