Giter VIP home page Giter VIP logo

gbksoftspinnerview's Introduction

GBKSoftSpinnerView

Well customizing widget that can be used instead of native Spinner to show dropdown list.
SpinnerView extends TextView, so you can apply any attributes that available for TextView.
It makes customizing process easy.

Installation

Add to the top level gradle file:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add to the app level gradle:

dependencies {
        implementation 'com.github.gbksoft:GBKSoftSpinnerView:v1.0.1'
}

Layout

<com.gbksoft.spinnerview.SpinnerView
        android:id="@+id/spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:padding="8dp"
        android:hint="Test hint"
        android:textColor="@color/colorAccent"
        android:textColorHint="@color/colorPrimary"
        app:sv_arrow_drawable="@drawable/ic_dropdown_arrow_animated"
        app:sv_arrow_tint="@android:color/holo_blue_bright"
        app:sv_dropdown_background="@drawable/bgn_dropdown"
        app:sv_dropdown_elevation="1dp"
        app:sv_dropdown_height="wrap_content"
        app:sv_dropdown_max_height="350dp"
        app:sv_dropdown_displayed_items_count="5"
        app:sv_dropdown_adapt_height_to_items_size="true"
         />

Customizing

There are some additional attributes to configure dropdown:

Attribute Info
sv_arrow_drawable right arrow icon that indicate dropdown status (expanded / collapsed)
sv_arrow_tint tint color for right arrow
sv_dropdown_background Background drawable for dropdown
sv_dropdown_elevation Dropdown elevation
sv_dropdown_max_height Dropdown max height (it will not expand more than this value)
sv_dropdown_displayed_items_count Set count of displayed items in dropdown view
sv_dropdown_adapt_height_to_items_size This flag will resize dropdown view size to match of full view height
sv_dropdown_height match_parent, wrap_content

To make arrow rotatable define sv_arrow_drawable like this:

<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/ic_dropdown_arrow"
    android:fromDegrees="0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toDegrees="180" />

Usage in code

To add items into dropdown you have to set adapter to SpinnerView. Adapter must extend SpinnerAdapter.

final SpinnerView spinner = findViewById(R.id.spinner);
spinner.setAdapter(spinnerAdapter); //Adapter must extend SpinnerAdapter

spinner.setOnItemSelectedListener(new SpinnerView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(int position) {
        //Item selected
    }
});

spinner.setOnNothingSelectedListener(new SpinnerView.OnNothingSelectedListener() {

    @Override
    public void onNothingSelected() {
        //Nothing selected
    }
});

Let us know

We'd be very happy if you sent links to your projects where you use our component. Just send us email to [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.