在微调删除pressed颜色 [英] Remove pressed color on Spinner
问题描述
我想删除蓝色(我测试我的霍洛应用程序)出现,当我点击一个微调。
I'd like to remove the blue color (I'm testing my app with Holo) appearing when I click on a Spinner.
我的code:
ArrayAdapter<String> array_adapter = new ArrayAdapter<String> (getActivity(),
R.layout.spinner_item, string_array);
array_adapter.setDropDownViewResource(R.layout.spinner_item);
Spinner spinner = (Spinner) getView().findViewById(R.id.spinner);
spinner.setAdapter(array_adapter);
spinner_item.xml
spinner_item.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/spinner_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:background="@drawable/item"
style="@style/EquidiaTheme.MySpinner" />
和item.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@android:color/transparent" />
<item android:state_selected="true" android:drawable="@android:color/transparent" />
<item android:drawable="@android:color/transparent" />
</selector>
这是行不通的。任何想法?
This doesn't work. Any idea?
推荐答案
我能摆脱,当我选择它的项目蓝色矩形时,我做到了这一点:
首先我声明,我想在values.xml用色彩:
I was able to get rid the blue rectangle on item when I select it when I done this: First I declare color that I want to use in values.xml:
<resources>
<drawable name="red_color">#ff0000</drawable>
<drawable name="blue_color">#0000ff</drawable>
<drawable name="green_color">#00ff00</drawable>
<drawable name="transparent_color">#00000000</drawable>
</resources>
比我定义Styles.xml自定义样式
Than I define custom style in Styles.xml
<resources>
<style name="Theme.Spinner" parent="android:Theme.Holo">
<item name="android:attr/listChoiceBackgroundIndicator">@drawable/transparent_color</item>
</style>
</resources>
在我的风格就是只能使用在资源定义的颜色(设置颜色,如:@android:彩色/ XXX或#XXX直接在风格上没有工作)
in the style I was able to use only colors defined in resources ( Setting color like: @android:color/XXX or #XXX directly in style didn't work)
毕竟我aplly了他们的活动。我使用Xamarin,可能code是:
After all I aplly the them on Activity. I use Xamarin so may code is:
[Activity( Label = "TestLayouts", MainLauncher = true, Icon = "@drawable/icon", Theme="@style/Theme.Spinner")]
但Android的应该是:
&LT;活动安卓主题=@风格/ Theme.Spinner&GT;
我用这个答案以供参考:
<一href=\"http://stackoverflow.com/questions/9250215/default-selector-background-in-clickable-views\">Default在可点击浏览选择背景
I use this answer for reference: Default selector background in Clickable Views
也摆脱对微调蓝色矩形本身是:
also to get rid the blue rectangle on spinner itself use:
<Spinner
android:background="@null"
您需要同时使用完全地消除蓝色rectable。
也可能这个属性的风格可以帮助你:
You need to use both to completly remove blue rectable. Also maybe this attributes in style may help you:
<item name="android:attr/colorPressedHighlight">#FF0000</item>
<item name="android:attr/colorLongPressedHighlight">#FF0000</item>
<item name="android:attr/listChoiceIndicatorSingle">@drawable/red_color</item>
这篇关于在微调删除pressed颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!