I think that's not exactly what he was looking for. Instead, try setting the InputAccessoryView property of the UITextField to a UIView that contains the widgets you need.
Pedro, Can you share the code you used to add the InputAccessoryView to an Xamarin.Forms.Edit control? I have like 50 fields on my various pages and I want to automatically add the InputAccessoryView to each of them, including a picker view if possible.
I can't share the exact code I'm using as that code is actually my client's code, but here is the idea:
Have a new Entry that extends Xamarin.Forms' Entry, like class MyEntry : Entry and create a custom renderer for it that extends EntryRenderer, like class MyEntryRenderer : EntryRenderer and on the OnElementChanged method you can set this.Control.InputAccessoryView to any UIView. You can follow this link to create an appropriate UIToolbar to set it here.
Then in your app just reference MyEntry instead of Entry and if the renderer is implemented correctly you'll see that the InputAccessoryView appears.
[assembly: ExportRenderer(typeof(MyEntry), typeof(MyEntryRenderer))]
namespace MyProject.iOS.Renderers
{
public class MyEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> args) {
{
base.OnElementChanged(args);
this.Control.InputAccessoryView = (...) ; // do your magic here
}
}
}
Thanks with this and about 4 other posts I was able to get a custom view with the close button (and a bunch of other fun buttons that I'm going to remove) working with Xamarin.Forms
With the information on this post, I was able to get this working in iOS, but I need to be able to replicate this functionality on Android. Can this be done in a similar fashion for Android by modifying the Renderer?
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged (e);
if (this.Element.Keyboard == Keyboard.Numeric)
{
// only want the Done on the numeric keyboard type
UIToolbar toolbar = new UIToolbar (new RectangleF (0.0f, 0.0f, (float)Control.Frame.Size.Width, 44.0f));
var doneButton = new UIBarButtonItem (UIBarButtonSystemItem.Done, delegate {
this.Control.ResignFirstResponder ();
Type baseEntry = this.Element.GetType();
if(baseEntrySendCompleted==null)
// use reflection to find our method
baseEntrySendCompleted = baseEntry.GetMethod("SendCompleted",BindingFlags.NonPublic|BindingFlags.Instance);
baseEntrySendCompleted.Invoke(this.Element,null); });
toolbar.Items = new UIBarButtonItem[] { new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace),doneButton };
this.Control.InputAccessoryView = toolbar;
}
}
Posts
This should be it, assuming that all Entry elements now get this keyboard (as I think MonoTouch.Dialog does by default):
I think that's not exactly what he was looking for. Instead, try setting the
InputAccessoryView
property of theUITextField
to a UIView that contains the widgets you need.Thanks much René, that's what I was looking for. With your hint and the following article I was able to implement what I needed ;-)
http://nnish.com/2013/12/02/adding-custom-buttons-to-ios-keyboard-in-c-xamarin/
Pedro, Can you share the code you used to add the InputAccessoryView to an Xamarin.Forms.Edit control? I have like 50 fields on my various pages and I want to automatically add the InputAccessoryView to each of them, including a picker view if possible.
Thanks
I can't share the exact code I'm using as that code is actually my client's code, but here is the idea:
Have a new
Entry
that extends Xamarin.Forms'Entry
, likeclass MyEntry : Entry
and create a custom renderer for it that extendsEntryRenderer
, likeclass MyEntryRenderer : EntryRenderer
and on theOnElementChanged
method you can setthis.Control.InputAccessoryView
to anyUIView
. You can follow this link to create an appropriate UIToolbar to set it here.Then in your app just reference
MyEntry
instead ofEntry
and if the renderer is implemented correctly you'll see that the InputAccessoryView appears.Thanks with this and about 4 other posts I was able to get a custom view with the close button (and a bunch of other fun buttons that I'm going to remove) working with Xamarin.Forms
With the information on this post, I was able to get this working in iOS, but I need to be able to replicate this functionality on Android. Can this be done in a similar fashion for Android by modifying the Renderer?
Thanks,
Doug
It was necessary to write my own renderer for Entry, so here is full code (all YOU need to do is just change your namespace
)...
public EntryDoneRenderer ()
{
}
}
@VinayKumar.9706 I'm getting null for the SendCompleted event. It used to work but not anymore.
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
@rocharocha
Wasn't working in iOS 10 for me, thanks for posting that code.
https://github.com/gruan01/XFControls/blob/master/XFControls/Src/AsNum.XFControls/Effects/KeyboardEnter.cs
https://github.com/gruan01/XFControls/blob/master/XFControls/Src/AsNum.XFControls.iOS/Effects/KeyboardEnterEffect.cs
https://github.com/gruan01/XFControls/blob/master/XFControls/Src/AsNum.Control.Droid/Effects/KeyboardEnterEffect.cs
@PedroLima @PaulDivan I have a PR sitting to make this easier: https://github.com/xamarin/Xamarin.Forms/pull/407
Has anybody done the equivalent on UWP, to provide a Done button on UWP phones?
I created a gist based on @PavelPenkava.8634 answer:
https://gist.github.com/yuv4ik/4592401836bd6bc54ac85fcc5cdbaa2f