2017-03-07 114 views
0

我正在嘗試使我的微調框的背景顏色變白。這是我想要對微調控制器做出的唯一改變,但是我看到的每個解決方案都需要製作自定義微調控制器,更改樣式,或者其他一些漫長而過度複雜的過程,以更改顏色。有沒有辦法輕鬆改變顏色。我喜歡創建drawable並將其設置爲背景的方法。我在下面找到的解決方案適用於api> = 23,但我需要的是最小爲19的東西。有沒有簡單的方法,還是必須創建自定義微調器才能更改顏色?這正是我試圖讓它看起來像。Android微調框顏色

Using drawable listed below for >= 23 api

<?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
     <item> 
      <color android:color="@color/splashColor" /> 
     </item> 

     <item android:gravity="center_vertical|right" android:right="8dp"> 
      <layer-list> 
       <item android:width="12dp" android:height="12dp" android:gravity="center" android:bottom="11dp"> 
        <rotate android:fromDegrees="45"> 
         <shape android:shape="rectangle"> 
          <solid android:color="#000000" /> 
          <stroke android:color="#aaaaaa" android:width="1dp"/> 
         </shape> 
        </rotate> 
       </item> 

       <item android:width="30dp" android:height="10dp" android:bottom="21dp" android:gravity="center"> 
        <shape android:shape="rectangle"> 
         <solid android:color="@color/splashColor"/> 
        </shape> 
       </item> 
      </layer-list> 
     </item> 
    </layer-list> 

使用不設置寬度/高度簡化版本(需要> = 23)看起來像這樣

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape> 
      <solid android:color="@android:color/white" /> 
     </shape> 
    </item> 
    <item> 
     <bitmap 
      android:gravity="end" 
      android:src="@drawable/arrow_dropdown" /> 
    </item> 
</layer-list> 

但它使高度過大,使得整個屏幕似乎關閉。我不知道如何改變高度23 23

回答

0

最後我用第二種方法,只是手動設置微調器的高度。這是微調代碼最終的樣子。

<Spinner 
     android:layout_width="match_parent" 
     android:layout_height="35dp" 
     android:background="@drawable/custom_spinner" 
     android:id="@+id/type" /> 

custom_spinner

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item> 
     <shape> 
      <solid android:color="@android:color/white" /> 
     </shape> 
    </item> 
    <item> 
     <bitmap 
      android:gravity="end" 
      android:src="@drawable/arrow_dropdown" /> 
    </item> 
</layer-list> 
0

您可以爲它設置一個主題屬性。

使用自定義命名空間並進行設置。

Ex。

<ProgressBar 
.... 
app:theme="@style/custom_style" 
/> 

其中custom_style是你的風格目錄定義爲:

<style name="custom_style" parent="Theme.AppCompat"> 
     <item name="colorControlNormal"><!--this color is not of importance --></item> 
     <item name="colorControlActivated">#FFFFFF</item> 
    </style> 

添加白色的進度顏色。適用於評分欄。假設也應該爲進度條工作。