組み込みのリソース ID android.R.layout.simple_spinner_dropdown_item を使用して SpinnerAdapter を作成しています
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
しかし、そのリソース ID が作成する textView には textColor Black があり、別の色が必要です。色を変更しながら、他のすべてを同じに保つ最良の方法は何ですか?
たとえば、xmlファイルで独自のtextViewレイアウトリソースを作成しようとすると
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/White"
/>
たとえば、パディングが異なるため、android.R.layout.simple_spinner_dropdown_item と同じようには動作しません。そう
- Is there a way of creating my own layout resource in an xml file which inherits everything from android.R.layout.simple_spinner_dropdown_item and allows me to override the textColor?
- Or is the complete definition of android.R.layout.simple_spinner_dropdown_item available somewhere?
- Or perhaps there's an even easier way somehow?
This question relates to another question that I've asked today (Can't change the text color with Android Action Bar drop-down navigation). I've realised that one answer to that question (and hence this question) is to create my own ArrayAdapter
class which inherits from ArrayAdapter<T>
so that I can always set the color in code whenever the ArrayAdapter gets used (see my answer to that question). But that seems like a very cumbersome solution :-|.
Changing a text color shouldn't be a hard task!