[英]Android Spinner Background color and Triangle Color
我的應用程序中有一個微調器,我想要一個自定義背景色和自定義三角形顏色。
設置每個不是問題,但是組合不起作用。 這是我當前的代碼
布局:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/languageSpinner"
android:textAlignment="center"
/>
活動:
Spinner languageSpinner = (Spinner) findViewById(R.id.languageSpinner);
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(this,
R.layout.item_spinner_lang,
new String[] { "DE", "EN", "SP" });
spinnerArrayAdapter.setDropDownViewResource(R.layout.item_spinner_dropdown_lang);
languageSpinner.setAdapter(spinnerArrayAdapter);
languageSpinner.setSelection(spinnerArrayAdapter.getPosition(prefLang), false);
//languageSpinner.setBackgroundColor(someColor); // if I use this, even the triangle has that color and vanishes
languageSpinner.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
languageSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
item_spinner_lang.xml:
<?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:textSize="20sp"
android:gravity="center"
android:textColor="#000000"
android:padding="5dip"
/>
微調框目前為白色。 但是我希望它是灰色的,三角形是白色的,文字也應該是白色的。 怎么做的?
嘗試為微調框使用自定義背景和樣式:
adapter.setDropDownViewResource(R.layout.spinner_item_drop_down);
spinner_item_drop_down.xml
:
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/SpinnerItemStyle"/>
SpinnerItemStyle
:
<style name="SpinnerItemStyle">
<item name="android:background">@drawable/spinner_bgd</item>
<item name="android:textColor">@color/white</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:gravity">center_vertical|start</item>
</style>
spinner_bgd.xml
:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:width="10dp"
android:height="10dp">
<bitmap
android:gravity="center_vertical|right"
android:src="@drawable/ic_custom_arrow"
android:tint="@color/gray" />
</item>
</selector>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.