nel progetto portatile aggiungere questo controllo
public class PlaceholderEditor : Editor
{
public static readonly BindableProperty PlaceholderProperty =
BindableProperty.Create("Placeholder", typeof(string), typeof(string), "");
public PlaceholderEditor()
{
}
public string Placeholder
{
get
{
return (string)GetValue(PlaceholderProperty);
}
set
{
SetValue(PlaceholderProperty, value);
}
}
}
nella vostra progetto Android aggiungi questo renderer:
[assembly: ExportRenderer(typeof(PlaceholderEditor), typeof(PlaceholderEditorRenderer))]
namespace Tevel.Mobile.Packages.Droid
{
public class PlaceholderEditorRenderer : EditorRenderer
{
public PlaceholderEditorRenderer() { }
protected override void OnElementChanged(ElementChangedEventArgs<Editor> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
var element = e.NewElement as PlaceholderEditor;
this.Control.Background = Resources.GetDrawable(Resource.Drawable.borderEditText);
this.Control.Hint = element.Placeholder;
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == PlaceholderEditor.PlaceholderProperty.PropertyName)
{
var element = this.Element as PlaceholderEditor;
this.Control.Hint = element.Placeholder;
}
}
}
}
nelle risorse> drawable aggiungere un file XML borderEditText.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="#FFFFFF"
android:endColor="#FFFFFF"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#F8B334" />
<corners android:radius="12dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#FFFFFF" android:angle="270" />
<stroke android:width="3dp" android:color="#ccc" />
<corners android:radius="12dp" />
</shape>
</item>
</selector>
Xaml: Header - xmlns:ctrls="clr-namespace:my control namespace;assembly= my assembly"
controllo:
<ctrls:PlaceholderEditor VerticalOptions="Fill" HorizontalOptions="StartAndExpand" Placeholder="add my comment title">
</ctrls:PlaceholderEditor>
fonte
2016-04-06 13:07:03
Si noti che la voce "su misura" in
IronRod
CornerRadius 6, BorderColor LightGray e BorderWidth .5f corrispondono meglio al bordo predefinito per Entry. –
Un po 'più di spiegazione e questa risposta sarebbe abbastanza buona per la voce di un blog! –