【问题标题】:Make Keyboard popup automatically on entry输入时自动弹出键盘
【发布时间】:2019-09-12 21:15:52
【问题描述】:

我在 Xamain 表单中使用网格,我想在选择事件上调用我认为做这个词 wok 的键盘。

我正在使用插件对话工具包来显示数字条目,但我的问题是键盘仅在具有焦点时才显示在文本框上我如何强制键盘出现以便用户不必点击进入领域。

 new Entry()
 {
                Keyboard = Keyboard.Numeric
 };

 var resultQty = await Plugin.DialogKit.CrossDiaglogKit.Current.GetInputTextAsync("Test", $"Please goto Bin {item.BinName} , and enter the visible stock of the item." + item.Name, null, Keyboard.Numeric);

Dialog kit 中的代码显示它试图将焦点放在输入字段上。

<ContentView.Content>
    <StackLayout Padding="10" BackgroundColor="White" VerticalOptions="CenterAndExpand" Margin="25">
        <Label FontAttributes="Bold" FontSize="Large" Text="{Binding Title}"/>
        <Label FontSize="Large" Text="{Binding Message}"/>
        <Entry x:Name="txtInput" Keyboard="{Binding Keyboard}"/>
        <StackLayout Margin="10" Orientation="Horizontal">
            <Button Text="{Binding OK}" Clicked="Confirm_Clicked" HorizontalOptions="FillAndExpand"/>
            <Button Text="{Binding Cancel}" Clicked="Cancel_Clicked" HorizontalOptions="FillAndExpand"/>
        </StackLayout>
    </StackLayout>
</ContentView.Content>

您会在这里看到对话套件调用上述几个这样的

public Task<string> GetInputTextAsync(string title, string message,string currentText = null, Keyboard keyboard = null)
{           
        if (keyboard == null) keyboard = Keyboard.Default;
        var cts = new TaskCompletionSource<string>();
        var _dialogView = new Plugin.DialogKit.Views.InputView(title, message,currentText,keyboard);
        _dialogView.FocusEntry();
        _dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
        PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });
        return cts.Task;
  }

正如你所看到的那样,它的位置是错误的,因为它在弹出视图之前是错误的。

public void FocusEntry() { txtInput.Focus(); }

【问题讨论】:

  • 只调用条目的焦点事件
  • @Jason 该条目位于插件对话框工具包中,除了告诉它显示数字文本框外,我无法控制它。
  • @Jason 我试图让它弹出,但它仍然没有工作输入字段在 rg 弹出窗口中。
  • @Jason 请看我上面的编辑。
  • @rogue39nin 鉴于这是一个外部库,您可以:创建一个包含更改的拉取请求并希望维护者“快速”响应,或者您可以进行 PR 但同时分叉项目并进行更改并使用 dll,直到 PR 被合并并且您的更改成为原始 repo 的一部分。

标签: xamarin.forms


【解决方案1】:

我做了一些测试,发现您应该在PopUp 之后调用FocusEntry 以强制键盘自动出现。

private async void Button_Clicked(object sender, EventArgs e)
{
    var resultQty = await GetInputTextAsync("Test", $"Please goto Bin, the visible stock of the item.", null, Keyboard.Numeric);
}

public async Task<string> GetInputTextAsync(string title, string message, string currentText = null, Keyboard keyboard = null)
{
    if (keyboard == null) keyboard = Keyboard.Default;
    var cts = new TaskCompletionSource<string>();
    var _dialogView = new Plugin.DialogKit.Views.InputView(title, message, currentText, keyboard);
    _dialogView.Picked += (s, o) => { cts.SetResult(o); PopupNavigation.PopAsync(); };
    await PopupNavigation.PushAsync(new PopupPage { Content = _dialogView });

    //Call the FocusEntry after PopUp
    _dialogView.FocusEntry();

    return await cts.Task;
}

【讨论】:

  • 嗨,杰克,我尝试使用 install google gboard 时仍然首先出现弹出窗口,所以确实如此。和用户在弹出之前实际进入该字段
  • 对不起,我没有明白你的意思,当我测试上面的代码时,键盘在用户输入之前弹出,这是你想要的吗?
  • 杰克我使用的是 huweii y9 2019,这不会发生在我的身上,即使我将代码调整为与我删除 nuget 引用并指向我的代码相同的弹出窗口仍然会首先出现我刚刚编译的本地 dll
  • @rogue39nin 因此,在 Github 上打开一个问题或创建一个拉取请求会更好地帮助您,因为它是一个第三方库。我在 iOS 模拟器上对其进行了测试,它在我这边也能正常工作。
猜你喜欢
  • 2011-06-07
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
  • 2011-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多