2015-03-02 66 views
-1

在我的项目,我必须在动作条充气这个自定义布局:如何更改微调文本颜色在动作条

Link to image

但我想有白色的微调文本。 我在网上看到过很多关于此的主题,但我无法解决问题。 我该如何解决这个问题?如何通过将其设置为白色来更改我的微调器的文本颜色?

编辑: 微调的XML代码是这样的:

<Spinner 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:textColor="#ffffff" 
    android:id="@+id/spinner"></Spinner> 

这很简单,我试过很多东西,但没有什么..

+0

我看不到你的形象。请显示您的微调器XML代码。 – joao2fast4u 2015-03-02 23:03:38

+0

您是否尝试过更改自定义布局中的文本颜色? – Kony2013 2015-03-02 23:04:39

+0

@ Kony2013是的,我试过但不起作用 – quasiaffatto 2015-03-02 23:08:23

回答

0

在你的活动,你应该有这样的事情: (基本上你所得到的微调,并设置它的适配器此适配器是负责加油吧)

Spinner spinner = (Spinner) findViewById(R.id.your_spinner_id); 
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.your_selected_spinner_item, myArrayList<String)); 

adapter.setDropDownViewResource(R.layout.your_dropdown_item); 
spinner.setAdapter(adapter); 

而且你可以拥有这个XML :(把它们放在RES /布局)

your_selected_spinner_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myLayoutID" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:textColor="#ffffff" 
android:textSize="20sp"/> 

而且还 your_dropdown_item.xml

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/myDropdownLayoutID" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:textColor="#ffffff" 
android:textSize="20sp"/> 
0

创建版式文件是这样的:

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/spinner_ref_id" 
    android:layout_width="match_parent" 
    android:padding="20dp" 
    android:textColor="#fff" 
    android:textSize="20sp" 
    android:text="Hello" 
    android:layout_height="wrap_content"> 

</TextView> 

假设您正在使用ArrayAdapter作为Spinner Adapter。

希望它有帮助!

+1

它的工作原理,非常感谢! – quasiaffatto 2015-03-02 23:38:24