标签:android android-spinner android-actionbar
我认为这是一个简单的问题,但我无法找到我的具体问题的答案.
我已经阅读了this great article,并且想要在动态栏上的Android下拉列表中设置所选项目的背景颜色(我没有使用Sherlock而我正在瞄准ICS),如下面的图像链接中所述:
到目前为止,我已经以这种方式设置了我的主题:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
</style>
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">@drawable/ad_selectable_background</item>
</style>
</resources>
这是我的ad_selectable_background.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
<item android:state_pressed="true" android:drawable="@android:color/holo_blue_light" />
<item android:drawable="@android:color/transparent" />
</selector>
我的下拉视图资源是:
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
按下状态有效,但是当您打开菜单时,不会显示任何选项.
我想使用选择器将其设置为holo_blue_light,但我无法使用XML找到正确的语法.
如果可能的话(我没有使用任何代码),我正在寻找一个只有XML的答案.谢谢!
解决方法:
显然,这很简单!
我必须编辑ad_selectable_background.xml以使用已检查状态(正如我之前所做的那样,但我错过了下面的主题):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime" >
<item android:state_pressed="false" android:state_checked="true" android:drawable="@android:color/holo_blue_light" />
<item android:state_pressed="true" android:drawable="@android:color/holo_blue_light" />
<item android:drawable="@android:color/transparent" />
</selector>
然后通过添加android:spinnerDropDownItemStyle项目并禁用checkMark(因为我不想要单选按钮)来编辑主题,这样:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<item name="android:dropDownListViewStyle">@style/MyDropDownListView</item>
<item name="android:spinnerDropDownItemStyle">@style/MySpinnerDropDownItem</item>
</style>
<style name="MyDropDownListView" parent="android:style/Widget.Holo.ListView.DropDown">
<item name="android:listSelector">@drawable/ad_selectable_background</item>
</style>
<style name="MySpinnerDropDownItem" parent="android:style/Widget.DropDownItem.Spinner">
<item name="android:background">@drawable/ad_selectable_background</item>
<item name="android:checkMark">@null</item>
</style>
</resources>
标签:android,android-spinner,android-actionbar 来源: https://codeday.me/bug/20190825/1717711.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。