Material design Spinner using TextInputLayout.OutlinedBox styling

前端 未结 8 1188
暗喜
暗喜 2021-02-05 11:31

I am currently using Material Design TextInputLayout OutlinedBox as shown below:

        

        
8条回答
  •  悲哀的现实
    2021-02-05 11:56

    I am assuming you want to have an Exposed drop-down menu inside the TextInputLayout I had the same problem, what you can do is use AutoCompleteTextView inside your TextInputLayout as in the following in the XML. here's an example of how I approached the issue.

    
    
                
    
    
    
    
            
    
    
    
                
    
            
    
    
            
    
        
    

    You will also need an item layout resource to populate the dropdown popup. The example below provides a layout that follows the Material Design guidelines.

    res/layout/dropdown_menu_popup_item.xml

    
    

    In your class add the following code depending on what you want.

    String[] type = new String[] {"Bed-sitter", "Single", "1- Bedroom", "2- Bedroom","3- Bedroom"};
    
            ArrayAdapter adapter =
                    new ArrayAdapter<>(
                            this,
                            R.layout.dropdown_menu_popup_item,
                            type);
    
            AutoCompleteTextView editTextFilledExposedDropdown =
                    findViewById(R.id.filled_exposed_dropdown);
            editTextFilledExposedDropdown.setAdapter(adapter);
    

    incase this doesn't help kindly check Exposed Dropdown Menus in material design page. [https://material.io/develop/android/components/menu/][1]

    This is my first answer on stack overflow I hope it helps.

提交回复
热议问题