On Android, you can do this with style.
Resources / values-v21 / styles.xml
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="myTheme" parent="android:Theme.Material"> <item name="android:buttonStyle">@style/noPaddingButtonStyle</item> </style> <style name="noPaddingButtonStyle" parent="android:Widget.Material.Button"> <item name="android:paddingLeft">0dp</item> <item name="android:paddingRight">0dp</item> </style> </resources>
AndroidManifest.xml
Set a custom theme as the application theme.
<application android:label="$safeprojectname$" android:theme="@style/myTheme"></application>
It sets the left and right margin to 0dp
. The default style is indented.
This works on Android> = 5. If you want to support lower versions of Android, you need to add several style folders and use other basic themes like Theme.Holo
or Theme.AppCompat
.
Or you will go to 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<Button> e) { base.OnElementChanged(e); Control?.SetPadding(0, Control.PaddingTop, 0, Control.PaddingBottom); } } }
source share