2017-04-05 19 views
1

私はSpinner TextViewの色を変更しようとしています。私はプログラムでそれを行う必要があります。私は私の個人的なアダプタとリソースビューを持っています。 (私がポップアップsipnnerのテキストの色、somenthigが選択されたときにユーザーのレイアウトに表示されたテキストのみを変更したくない)Androidの変更SpinnerのTextViewの色

これは私のコードです:

PersonalArrayAdapter spAdapterInfraccion = new PersonalArrayAdapter(getContext(), 
      R.layout.item_spinner, 
      infraccionList); 

spinner.setAdapter(spAdapter); 

item_spinner.xml:

<?xml version="1.0" encoding="utf-8"?> 
<co.my.app.utils.CustomTextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/text1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceListItemSmall" 
    android:gravity="center_vertical" 
    android:paddingStart="?android:attr/listPreferredItemPaddingStart" 
    android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" 
    android:minHeight="?android:attr/listPreferredItemHeightSmall" /> 

これは私が試した方法ですが、nullを返します。

CustomTextView text = (CustomTextView)view.findViewById(R.id.text1); 
text.setTextColor(getContext().getColor(R.color.black)); 
+0

「表示」が何も表示されずにわからない – Flikk

答えて

1

あなたはこの試みる可能性があります -

public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { 
int index = adapterView.getSelectedItemPosition(); 
((TextView) spinner.getSelectedView()).setTextColor(getResources().getColor(R.color.Blue)); 

は、それはあなたを助けることを願っています。 :)

関連する問題