/ Spinner

Custom spinner that inspired by instagram language chooser

Custom spinner that inspired by instagram language chooser

JRSpinner

Custom spinner that inspired by instagram language chooser.

JRSpinnerv

What's new

What's new in version 0.2.4

1. Add check icon in selected item
2. Add reset function to reset JRSpinner selected item
3. Bug fixing to support backward compatibility

Gradle install

Make sure there is jcenter repository in your project level build.gradle

allprojects {
    repositories {
        ..
        jcenter()
    }
}

Implement the dependency to your app-level build.gradle

dependencies {
  ..
  implementation 'jrizani:jrspinner:$version'
}

How to use

Declare the view in your layout

<jrizani.jrspinner.JRSpinner
                android:id="@+id/spn_my_spinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/choose"
                android:textColor="@color/colorPrimary"
                app:backgroundTint="@color/colorPrimary"
                app:jrs_title="Choose"
                app:jrs_icon_tint="@color/colorPrimary"/>

Attribute

Attribute Description Default Value
android:hint hint of spinner nothing
android:textColor color of text default text color
app:backgroundTint tint of spinner, in default it is change underline color of spinner default edittext background tint
android:background if you want your own background of spinner, you can use it default edittext background
app:jrs_title there is the title of the spinner dialog "Choose"
app:jrs_icon_tint color tint of expand icon #99000000

You also can set the parameter programmatically

private JRSpinner mySpinner;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mySpinner = findViewById(R.id.spn_my_spinner);

    mySpinner.setItems(getResources().getStringArray(R.array.tesItems)); //this is important, you must set it to set the item list
    mySpinner.setTitle("Choose item programmatically"); //change title of spinner-dialog programmatically
    mySpinner.setExpandTint(R.color.color_default); //change expand icon tint programmatically

    mySpinner.setOnItemClickListener(new JRSpinner.OnItemClickListener() { //set it if you want the callback
        @Override
        public void onItemClick(int position) {
            //do what you want to the selected position
        }
    });
}

Additional

If you want the spinner has a floating label, you can wrap this spinner in Text input layout:

android.support.design.widget.TextInputLayout or com.google.android.material.textfield.TextInputLayout if you use androidx artifact

 <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/til"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:hintEnabled="true">

            <jrizani.jrspinner.JRSpinner
                android:id="@+id/spn_my_spinner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/my_hint"
                android:textColor="@color/colorPrimary"
                app:backgroundTint="@color/colorPrimary"
                app:jrs_title="Choose"
                app:jrs_icon_tint="@color/colorPrimary"/>

</com.google.android.material.textfield.TextInputLayout>

Example

You can found the example code here.

There is the sample gif

sample

GitHub