Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing spinner arrow, Appcompat v21

i have activities which i themed with my custom theme, but for spinner i choosed to style it with Appcompat v21 but i got this : enter image description here

So how to change the Spinner arrow to be black or blue if is there a way ?

i found this as similar question but doesn't have any answer : https://stackoverflow.com/questions/28561105/add-custom-spinner-arrow here is my spinner :

<Spinner
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/spinner2"
        android:layout_marginTop="10dp"
        android:layout_centerInParent="true" />

i used this to style the spinner:

 <style name="MyTheme.SpinnerAppTheme" parent="Widget.AppCompat.Spinner">
    </style>

this is how i use the adapter

   ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                getBaseContext(), R.array.listMedRes, android.R.layout.simple_spinner_item);

i just want to theme the spinner , thanks alot

like image 592
Charaf Eddine Mechalikh Avatar asked May 09 '15 02:05

Charaf Eddine Mechalikh


People also ask

What is actionbarcompat V21?

AppCompat (aka ActionBarCompat) started out as a backport of the Android 4.0 ActionBar API for devices running on Gingerbread, providing a common API layer on top of the backported implementation and the framework implementation. AppCompat v21 delivers an API and feature-set that is up-to-date with Android 5.0 In this...

What is the use of appcompatspinner?

AppCompatSpinner. A Spinner which supports compatible features on older versions of the platform, including: Allows dynamic tint of its background via the background tint methods in ViewCompat. Allows setting of the background tint using R.attr.buttonTint and R.attr.buttonTintMode.

What's new in appcompat?

Updated dependencies: appcompat updated many of its transitive dependencies to support new functionality and fixes: Updated from Lifecycle 2.0.0 to Lifecycle 2.3.1. androidx.appcompat:appcompat:1.3.0-rc01 and androidx.appcompat:appcompat-resources:1.3.0-rc01 are released.

How do I add a dependency on appcompat?

To add a dependency on Appcompat, you must add the Google Maven repository to your project. Read Google's Maven repository for more information. Add the dependencies for the artifacts you need in the build.gradle file for your app or module: dependencies { def appcompat_version = "1.2.0" implementation "androidx.


1 Answers

Might be late but better late than never. To respond to your question: "Is there a way to use it only in spinner?". The answer is yes, refer to the code below.

Add this code to your theme or style file

<style name="customSpinnerTheme" parent="yourAppThemeThatUseAppCompat21">
    <item name="colorControlNormal">#eaeaea</item>
    <item name="colorControlActivated">#000000</item>
    <item name="colorControlHighlight">#000000</item>
</style>

Then in your XML that use spinner you can add this line

android:theme="@style/customSpinnerTheme"

e.g.

<Spinner
    android:theme="@style/customSpinnerTheme"
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:spinnerMode="dialog" />
like image 108
HendraWD Avatar answered Sep 21 '22 20:09

HendraWD