Android的:不能风格的微调分 [英] Android: Cannot style spinner divider
问题描述
我试图创建一个主题为我的第一个Android应用程序,这是推动我拐弯。我终于设法弄清楚如何样式下拉列表中的项目,但现在我不能改变列表项之间的分隔的颜色。我已经搜查计算器类似的问题,并试图数十组合,但似乎没有任何工作。
I'm trying to create a theme for my first Android app, and it is driving me round the bend. I finally managed to figure out how to style items in a dropdown list, but now I can't change the colour of the divider between list items. I have searched similar questions on stackoverflow, and tried dozens of combinations, but nothing seems to work.
下面是我的styles.xml文件(简称为清楚起见):
Here is my styles.xml file (abbreviated for clarity):
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.Light">
<item name="android:spinnerStyle">@style/spinnerStyle</item>
<item name="android:spinnerDropDownItemStyle">@style/spinnerDropDownItemStyle</item>
<item name="android:dropDownListViewStyle">@style/spinnerListViewStyle</item>
</style>
<style name="spinnerStyle" parent="@android:style/Widget.Spinner">
<item name="android:background">@drawable/my_theme_spinner</item>
</style>
<style name="spinnerDropDownItemStyle" parent="@android:style/Widget.DropDownItem.Spinner">
<item name="android:background">@drawable/my_theme_spinner_item</item>
<item name="android:paddingLeft">5dp</item>
<item name="android:gravity">center_vertical</item>
</style>
<style name="spinnerListViewStyle" parent="@android:style/Widget.ListView.DropDown">
<item name="android:height">3dp</item>
<item name="android:dividerHeight">3dp</item>
<item name="android:divider">@color/divider</item>
</style>
</resources>
无论我做什么,我只是得到物品之间的1DP浅灰色分频器(这勉强可以看见我的浅色列表项的背景) - 无论是高度还是分频器以往任何时候都受到影响(我也试着设置颜色到一个可拉伸,也没有效果)。我究竟做错了什么?
No matter what I do, I just get a 1dp light grey divider between items (which can barely be seen with my light coloured list item background) - neither the height nor colour of the divider is ever affected (I also tried setting it to a drawable, also with no effect). What am I doing wrong?
推荐答案
我有一个非常简单的活动与微调,它适用于以下。我看到的唯一区别是,你有一个&LT;项目名称=机器人:身高&GT; 3DP和LT; /项目&GT;
,我没有,在所有。
I have a very simple Activity with the Spinner and it works for the following. The only difference I see is that you have a <item name="android:height">3dp</item>
and I don't have that at all.
<style name="TestSpinnerStyle" parent="android:style/Widget.ListView.DropDown">
<item name="android:divider">#ff0000</item>
<item name="android:dividerHeight">5dp</item>
</style>
<style name="SampleTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:dropDownListViewStyle">@style/TestSpinnerStyle</item>
</style>
和我的活动我有:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
List<String> list = new ArrayList<String>();
list.add("list 1");
list.add("list 2");
list.add("list 3");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(dataAdapter);
,然后为主要布局我有以下的XML:
and then for the main layout I have the following XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, StylingActivity"
/>
<Spinner android:id="@+id/spinner"
android:layout_width="250dp"
android:layout_height="40dp"
/>
</LinearLayout>
下面是截图
如果你不能得到它从那里工作,我可以推高了整个事情到GitHub库为你。
If you can't get it to work from there, I can push up the entire thing to a github repo for you.
这篇关于Android的:不能风格的微调分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!