Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to make Custom Spinner using material design

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 2.60k
    Comment on it

    In the below example code I have created a Custom Spinner. Here first, I have added spinner library in build.gradle file. After that, I have added Spinner layout in activity_main.xml layout. In MainActivity I have added items name in String.

    You can see below example code it clearly describes "How to make Custom Spinner using spinner material design library?".

    Step(1)-I have added first material design spinner dependency to Grandle file -

    Introduction of library:- There is a material design spinner library which provides us the facility to create or to add a customize spinner in your application.

         compile 'com.weiwangcn.betterspinner:library-material:1.1.0'

    Step(2)-Added spinner layout in activity_main.xml-

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="16dp"
        android:orientation="vertical">
    
        <com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
            android:id="@+id/android_material_design_spinner"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Company Name "
            android:textColorHint="#d10e3b"
            app:met_floatingLabel="normal" />
    </LinearLayout>

    Step(3)-MainActivity-

    In MainActivity I have added Company  names in String array List then I have created ArrayAdapter for using String Array list

    public class MainActivity extends AppCompatActivity {
    
            String[] SPINNERLIST = {"Evon tech", "Microsoft", "Ericsson", "Genpack"};
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
    
                ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                        android.R.layout.simple_spinner_dropdown_item, SPINNERLIST);
                MaterialBetterSpinner materialDesignSpinner = (MaterialBetterSpinner)
                        findViewById(R.id.android_material_design_spinner);
                materialDesignSpinner.setAdapter(arrayAdapter);
            }
        }

     

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: