Xamarin.Forms: Remove padding inside Button

前端 未结 4 773
无人及你
无人及你 2021-02-13 07:12

I want to have a small button. The height of the button is 30. On some plattforms (Android, UWP) the text inside the button is cut off. That\'s because there is a padding betwee

4条回答
  •  青春惊慌失措
    2021-02-13 07:37

    On Android, you can do this with styling.

    Resources/values-v21/styles.xml

    
    
      
    
      
    
    

    AndroidManifest.xml

    Set custom theme as application theme.

    
    

    It's setting the left and right margin to 0dp. The default style has a padding.

    This is working on Android >= 5. If you want to support lower android versions, you have to add multiple style folders and use other base themes like Theme.Holo or Theme.AppCompat.


    Or you go for the Renderer:

    using App6.Droid;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.Android;
    
    [assembly: ExportRenderer(typeof(Button), typeof(ZeroPaddingRenderer))]
    namespace App6.Droid
    {
        public class ZeroPaddingRenderer : ButtonRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs

提交回复
热议问题