Reputation: 34
I am working in a Xamarin Forms APP, we want to go through different entries (not using TabIndex because we need a custom logic), but we want to keep the keyboard always on during looping through entries. We are using ReturnCommand to Focus the NEXT entry.
Upvotes: 0
Views: 1151
Reputation: 15011
Create a CustomEntryRenderer in your Android project :
[assembly: ExportRenderer(typeof(Entry), typeof(CustomEntryRenderer))]
namespace your namespace
class CustomEntryRenderer:EntryRenderer
{
public CustomEntryRenderer(Context context):base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
}
}
and add this in your MainActivity:
private bool _lieAboutCurrentFocus;
public override bool DispatchTouchEvent(MotionEvent ev)
{
var focused = CurrentFocus;
bool customEntryRendererFocused = focused != null && focused.Parent is CustomEntryRenderer;
_lieAboutCurrentFocus = customEntryRendererFocused;
var result = base.DispatchTouchEvent(ev);
_lieAboutCurrentFocus = false;
return result;
}
public override Android.Views.View CurrentFocus
{
get
{
if (_lieAboutCurrentFocus)
{
return null;
}
return base.CurrentFocus;
}
}
Upvotes: 1