这是你可以做到的:
[assembly: ExportRenderer(typeof(Entry), typeof(EntryRendererImplementation))]
namespace MyProject.Droid.Renderers
{
public class EntryRendererImplementation : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.Background = this.Resources.GetDrawable(Resource.Drawable.RoundedCornerEntry);
Control.SetPadding(10,10,10,3);
}
}
}
}
您必须在您的 android 项目的Resources/drawable/RoundedCornerEntry.xml中创建此文件
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" >
<shape android:shape="rectangle">
<gradient
android:startColor="@color/entry_background"
android:endColor="@color/entry_background"
android:angle="270" />
<stroke
android:width="1dp"
android:color="@color/entry_border" />
<corners
android:radius="6dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:startColor="@color/entry_background"
android:endColor="@color/entry_background"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#c6c6c6" />
<corners
android:radius="6dp" />
</shape>
</item>
</selector>
当然,您需要更新Resources/values/colors.xml文件,例如:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="entry_background">#ffffff</color>
<color name="entry_border">#BDBDBD</color>
</resources>
给你!