Navigation drawer rounded corner background for items

前端 未结 3 1048
余生分开走
余生分开走 2021-02-09 17:40

I want to have a rounded corner for the items in navigation drawer like this :

it\'s an example of material design in material.io website

is it possible

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 18:27

    First, I recommend you move to Flutter, it is more intuitive and you got the best integration flow of Material guidelines.

    Now, for add round corners, color, font and padding to a checked item with XML and Android Studio, you have the 'app' attributes on NavigationView:

    
    
    
    

    With itemIconTint and itemTextColor you set the color config of the hole item (icon and text) when is checked or non-checked. First, do res > new > directory, and name directory as 'color'. Then, create the color resource file in color directory with new > color resource file > custom_color_config (name) and put this:

    
    
        
        
    
    

    The item with the state_checked=true attribute will apply his color to the current navigation checked item.

    To add the background rounded box, create in drawable directory a new drawable resource file to set at itemBackground later. So, new > drawable resource file > custom_drawable_resource (name) and put this:

    
    
        
    
            
                
                
            
    
        
    
    

    And next, create again a second color resource file in color directory to associate with the solid color attribute in file custom_drawable_resource (new_color_resource_name) and there put this:

    
    
        
        
    
    

    And VOILA! just add to text appearance a custom style with some semi bold font.

    PD: Sorry if I've a bad english, I usually read more than I write, regards from MX.

提交回复
热议问题