Issue
I am attempting to make the background color of my spinner white. That's the only change I want to make to the spinner but every solution I see either requires making a custom spinner, changing the styles, or some other long and overly complicated process to just change the color. Is there a way to change the color easily. I enjoyed the method of creating a drawable and setting that as a background. Solution I found below works for api >= 23 but I need something with a min of 19. Is there an easy way or do I have to create a custom spinner just to change the color? This is what I am trying to make it look like.
<?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>
Using a simplified version without setting width/height (requires >= 23) looks like this
<?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>
but it makes the height too large, making the whole screen seem off. I am unaware of a way to change the height pre 23
Solution
In the end I used the second method and just manually set the height of the spinner. Here is what the spinner code looks like in the end.
<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>
Answered By - Ubarjohade
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.