边框半径按钮在android

时间:2017-03-11 07:27:31

标签: android xamarin xamarin.forms

我使用Xamarin.Forms,我尝试设置BorderRadius = 10BorderRadius = Device.OnPlatform<int>(iOS: 0, Android: 10, WinPhone: 10)。在UWP上它是可以的(两种方式)但在Android BorderRadius中不适用

2 个答案:

答案 0 :(得分:8)

  

按钮我想从Button

更改BorderRadius

问题在于Xamarin Forms for Android的ButtonRenderer。 Android有两种ButtonRenderer

Xamarin.Forms.Platform.Android命名空间下的

ButtonRendererXamarin.Forms.Platfrom.Android.AppCompat命名空间下的ButtonRenderer

默认情况下,在Xamarin.Forms中,它将使用ButtonRenderer命名空间下的Xamarin.Forms.Platfrom.Android.AppCompat来渲染按钮,但此渲染器不会为Button创建边框,因此BorderRadius属性不适用于使用此渲染器渲染的按钮。

要解决此问题,您可以使用Custom Renderer创建自己的自定义按钮,并使用ButtonRenderer命名空间下的Xamarin.Forms.Platform.Android进行渲染。

要为Button创建自定义渲染器,可以参考此discussion

答案 1 :(得分:0)

另一种解决方案

这样更改渲染器构造函数。

public CustomButtonRenderer(Context context) : base(context)
{

}