- #Android studio spinner first element change color android#
- #Android studio spinner first element change color code#
- #Android studio spinner first element change color free#
I used the down arrow from the free feather icon pack. The last thing we’ll need, is a dropdown icon which will be placed at the end of the TextInputLayout.
#Android studio spinner first element change color code#
Next, we’re going to create a new filter_spinner_dropdown_bg.xml drawable and use the following code to shape it: Let’s begin with the color that we’ll use for the background of our dropdown. To learn more about the various available styles and customization options, take a look at Google's Menus - Material Design documentation. This in combination with the custom style we’re assigning to the TextInputLayout, will allow the AutoCompleteTextView to function like a spinner when clicked. Pay attention to the inputType="none" line since that tells the AutoCompleteTextView that we’re not planning on entering any text details by hand.
Here we’re simply adding a TextInputLayout that contains an AutoCompleteTextView which will act as our dropdown. Let’s start by declaring the basic layout of a material exposed dropdown menu.
#Android studio spinner first element change color android#
I’m also going to be using V iewBinding for this tutorial, so make sure you enable it in your module’s adle by adding the following: android Designing the basic layout Let’s import the library into our project: implementation ‘:material:1.4.0’ On Android, this functionality can be implemented using a TextInputLayout along with a nested AutocompleteTextView which are both components of Android’s material library. Some variations can accept user-entered input. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.Final exposed dropdown menu What are exposed dropdown menus?Įxposed dropdown menus display the currently selected menu item above the list of options. If the response is helpful, please click " Accept Answer" and upvote it. spinner.SetPopupBackgroundDrawable(new ColorDrawable(Color.Rgb(255, 0, 0)))
If you get the color by RGB, you could use ColorDrawable to convert the color like following code. Var textView=view.FindViewById(Resource.Id.MytextView)
Public override View GetView(int position, View convertView, ViewGroup parent) Public override long GetItemId(int position) Public override int Count => planetNames.Count Public override string this => planetNames Public MyAdapter(MainActivity mainActivity, List planetNames) Public void OnNothingSelected(AdapterView parent) ((TextView)view.FindViewById(Resource.Id.MytextView)).SetTextColor() //Change selected text color Public void OnItemSelected(AdapterView parent, View view, int position, long id) Internal class myItemSelectedListener :, AdapterView.IOnItemSelectedListener (requestCode, permissions, grantResults) īase.OnRequestPermissionsResult(requestCode, permissions, grantResults) Public override void OnRequestPermissionsResult(int requestCode, string permissions, .Permission grantResults) Private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e) Spinner.OnItemSelectedListener = new myItemSelectedListener() Var adapter = new MyAdapter(this, planetNames) Spinner.ItemSelected += new EventHandler(spinner_ItemSelected) Spinner.SetPopupBackgroundDrawable(Resources.GetDrawable(_blue_grey_800)) Spinner spinner = FindViewById(Resource.Id.spinner) Set our view from the "main" layout resource Protected override void OnCreate(Bundle savedInstanceState) Public class MainActivity : AppCompatActivity Text color of the dropdown portion of the spinner: you need to create an custom adapter to achieve it. You can change the background color and text color of the dropdown portion of the spinner.Ĭhange the background color: you can use spinner.SetPopupBackgroundDrawable(Resources.GetDrawable(_blue_grey_800))