Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style TextView like a Spinner with appcompat v21

I want to make a TextView look like a spinner with the new Material style.

I managed to do it with "Widget.Material.Light.Spinner" style, but I didn't find any alternative in AppCompat (v21) resources. My xml:

<TextView
        android:id="@+id/sp_league_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        tools:text="Premier league"
        style="@android:style/Widget.Material.Light.Spinner"
        android:textColor="@android:color/white" />
like image 549
Idob Avatar asked Dec 06 '14 20:12

Idob


2 Answers

I'd go with:

style="@style/Widget.AppCompat.Spinner"

But feel free to pick another one: enter image description here

like image 100
TWiStErRob Avatar answered Sep 19 '22 08:09

TWiStErRob


The style solution didn't work for me, but I've found another solution:

I use AppCompatButton instead, and have this :

XML:

<android.support.v7.widget.AppCompatButton
 android:background="@drawable/abc_spinner_mtrl_am_alpha"
 ... />

Java:

((AppCompatButton)findViewById(...)).setSupportBackgroundTintList(new ColorStateList(new int[][]{new int[0]}, new int[]{0xff52A1E8}));

EDIT: seems it won't work well anymore, but found another solution :

<style name="Widget.MyTheme.HeaderBar.Spinner" parent="Widget.AppCompat.Light.Spinner.DropDown.ActionBar">
</style>

It's true that it's for the action bar , but it should work for other cases too.

like image 24
android developer Avatar answered Sep 23 '22 08:09

android developer