Spinner inner padding is larger on Android 6.0.1

后端 未结 2 1989
借酒劲吻你
借酒劲吻你 2020-12-31 03:18

Intro:

With the new release of Android 6.0.1, seems like Android made some changes on the Spinner component because by default, the inner padding ar

2条回答
  •  庸人自扰
    2020-12-31 03:40

    With minimal effort I was able to fix this by building a custom background for the spinner.

    Using AppCompatSpinner I had to create 2 xmls for the background, let's call this spinner_background.xml:

    1. First one goes to the drawable folder and looks like this, spinner_background.xml:

    
    
        
        
    
    

    Where selector_background_borderless is a plain selector like(I added the minimal items you need, you could explore it's ripple alternative for v21+. In fact I would recommend you to do so):

    
    
        
        
    
    

    And bg_spinner_anchor is a 9patch PNG for the caret. I used these assets: bg_spinner_anchor

    2. The second one goes to the drawable-v23 folder to properly support ripple and looks like this, spinner_background.xml:

    
    
        
    
        
    
    

    Where ic_spinner_caret is a vector used from the Android source code looking like this. You should add also add this to your drawable-v23 folder:

    
    
        
    
    

    Credits go to alanv from the Android UI toolkit for Guidance!

提交回复
热议问题