Customize divider / separator in dropdown of an AutocompleteTextview

前端 未结 4 1814
情深已故
情深已故 2020-12-16 14:14

I\'ve seen this question asked some other times on the site, but no one couldn\'t get any answer.

Is there any way to customize the appearance of the divider in the

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-16 14:48

    The answer from Mark is normally the best solution. However different versions of the AppCompat library have different behavior, regarding how android:dropDownListViewStyle affects other menus, like the system overflow/options menu. For example, in AppCompat version 23.0.1, it will not affect this menu in the ActionBar/Toolbar; whereas version 23.2.1 it will affect it, as explained here.

    If you want a style that is isolated to only affect the AutoCompleteTextView, it may not be possible. But an alternative way is to create the list divider image manually, as part of the layout of the dropdown list row:

    res/layout/autocomplete_list_row.xml

    
    
        
    
        
    
    
    

    res/drawable/divider.xml

    
    
        
        
    
    

    Then use this layout in your adapter for the AutoCompleteTextView:

    ArrayAdapter autoCompleteListAdapter = 
        new ArrayAdapter<>(context,
                           R.layout.autocomplete_list_row,
                           R.id.text, arrayList);
    

    Similar approach using ConstraintLayout here.

提交回复
热议问题