How to apply a theme to my spinner by code

1

I have the following code in which a spinner is created, I want to apply a style, but do not have any changes at the moment of running the application, am I doing it wrong? I'm missing something and I do not realize it? or is it impossible to apply a style from code to this widget?

Style Code:

<style name="SpinnerTheme" parent="Widget.AppCompat.Spinner">
    <item name="android:textSize">14sp</item>
    <item name="android:textAppearance">@style/TextAppearanceSpinnerItem</item>
</style>

<style name="TextAppearanceSpinnerItem" parent="Widget.AppCompat.TextView.SpinnerItem">
    <item name="android:textColor">@color/coloarAzulClaro</item>
</style>

Code to create spinner:

public void createSpinner(List<FormatoEnum> enumList) {
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(0, dpToPx(20), 0, 0);
    AppCompatSpinner spinner = new AppCompatSpinner(new ContextThemeWrapper(context, R.style.SpinnerTheme));
    spinner.setId(id());
    SpinnerAdapter adapter = new SpinnerAdapter(context, enumList);
    spinner.setLayoutParams(lp);
    spinner.setAdapter(adapter);
    bodyLayout.addView(spinner);
}
    
asked by Bourne 06.07.2016 в 17:23
source

0 answers