上の画像では、GAIN 3が選択されていますが、正しく表示されていないので、その色を暗い色に変更するにはどうすればよいですか。基本的に、選択したテキストの背景を暗い色に変更したいと思います。
com.jaredrummler.materialspinner.MaterialSpinner
Spinnerを使用しています。
これがJavaの実装です。
spinner.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {
@Override public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
text = spinner.getText().toString();
Log.e("Spinner Listener",text);
if(text.contains("GAIN 0")){
sendToDevice("F");
} else if(text.contains("GAIN 1")){
sendToDevice("G");
} else if(text.contains("GAIN 2")){
sendToDevice("H");
} else if(text.contains("GAIN 3")){
sendToDevice("I");
}
}
});
また、レイアウト項目は以下のようになります。
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinner"
app:ms_dropdown_max_height="350dp"
app:ms_dropdown_height="wrap_content"
android:textColorHighlight="#000000"
android:layout_width="130dp"
style="@style/spinner_style"
android:popupTheme="@android:style/ThemeOverlay.Material"
android:textColor="@color/blue"
android:layout_below="@+id/testmodetitle"
android:layout_height="wrap_content"
android:layout_marginTop="55dp"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_toEndOf="@+id/button1"
android:layout_marginStart="30dp" />
背景色やその他の色を変更するために、このライブラリにはいくつかの属性が用意されています。選択したアイテムの背景色を変更するには、以下のコードを使用します。
<com.jaredrummler.materialspinner.MaterialSpinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ms_background_selector="@drawable/selector_gray_white_spinner"
app:ms_dropdown_height="wrap_content"
app:ms_dropdown_max_height="350dp" />
名前を持つdrawableに1つのセレクターを作成します selector_gray_white_spinner.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@color/darkGray"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@color/darkGray"/>
<item android:state_focused="true" android:drawable="@android:color/white"/>
<item android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/white"/>
</selector>
color.xmlファイルに暗い色を追加します
<color name="darkGray">#acacac</color>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加