How to remove extra padding from button views in Xamarin Forms for Android?

后端 未结 3 985
执念已碎
执念已碎 2021-01-13 05:12

The button views on Xamarin Forms seem to get extra padding applied when deployed to Android. I have set Resources/values/styles.xml under my Android project to have all spa

3条回答
  •  梦毁少年i
    2021-01-13 05:54

    Try this:

    In your Android Project open your Styles.xml

    Inside the MyTheme.Base style (I am assuming is called like this based on the default Xamarin.Forms template) add the following line:

    @style/MyButton
    

    Create a new style with name MyButton

       
    

    In the Drawable folder add a new XML file called button_ripple.xml and paste the following code:

    
    
    
    
        
            
                
            
        
    
        
            
                
            
        
    
    

    This file is necessary because when the background of a button in Android is changed the ripple effect (the effect when tapping on it) is lost.

    If you don't care about the effect go back to the style file and the MyButton style can be just something like this:

    
    

    This might help you without CustomRenderers.-

提交回复
热议问题