Android Spinner Toolbar Tutorial HD

24.08.2016
In this Android spinner toolbar tutorial you will learn how to add a android custom toolbar by adding a spinner, when you select an item from android spinner it will show it in android toast message. Here is how to do it: - Open up styles.xml file that is located under values folder and then change the parent theme to: Theme.AppCompat.Light.NoActionBar - Open up activity_main.xml file and replace the hello world textview with a toolbar - Inside the toolbar we add a spinner - Now lets declare the toolbar and spinner in MainActivity.java file like this: Toolbar myToolbar = (Toolbar) findViewById(R.id.toolbar); Spinner mySpinner = (Spinner) findViewById(R.id.spinner); - Open strings.xml file and we need to create an string array that will hold the values for the spinner - In MainActivity.java class we create an ArrayAdapter that hold the values of string array for the spinner - To make the items inside the android spinner clickable, we need to call spinner setOnItemSelectedListener, then will work with onItemSelected method, so when you tap on item inside the spinner we will show a toast message with the selected item based on the position like this: Toast.makeText(MainActivity.this, mySpinner.getSelectedItem().toString(), Toast.LENGTH_SHORT) .show(); - We are done for this tutorial :) Source code is available at this link: https://github.com/codingdemos/CustomToolbar

Похожие видео

Показать еще