【问题标题】:Not to show keyboard when focusing a searchbox聚焦搜索框时不显示键盘
【发布时间】:2016-05-04 06:40:45
【问题描述】:

我正在开发一个应用程序(在 Xamarin.Forms 中),它将与外部条形码扫描仪一起使用,所以 我不需要显示每个触觉键盘时间我把焦点放在条目/搜索框/等上。

我该怎么做?

谢谢大家。

【问题讨论】:

  • 我正在尝试使用自定义渲染器,但找不到要修改的属性以实现此行为。
  • @thisOneGuy 很棒的 cmets,它可能是条形码“无线扫描仪”吗? OP请详细说明?即developer.xamarin.com/recipes/ios/input/keyboards/…
  • @thisOneGuy 我不明白你的问题。我需要搜索,但最终用户不使用触觉键盘,因为他使用的是外部条形码扫描仪。所以我想隐藏键盘。
  • 我需要搜索控件来在列表中的项目之间进行搜索。如果你能帮助我,我很感激,但我不明白你的问题。了解我为什么要使用此控件或我正在做的问题在这里有什么重要的??
  • 为什么没有一页用于扫描仪和一页用于搜索?

标签: c# keyboard hide xamarin.forms


【解决方案1】:

假设您不希望键盘在 Entry 上不显示任何内容,您可以在 Entry 的构造函数中将 Keyboard 属性设置为 null

var scannerEntry = new Entry
{
    Keyboard = null,
    Placeholder = "Scan an item"
};

由于 Xamarin.Forms API 未在 SearchBar 类上公开 Keyboard 属性,因此您可以编写 custom renderer。 iOS 实现可以在OnElementChanged 覆盖中使用ResignFirstResponder 来防止键盘显示:

[assembly: ExportRenderer(typeof(ScannerSearchBar), typeof(ScannerSearchBardRenderer))]
namespace HideKeyboard.iOS
{
    public class ScannerSearchBarRenderer : SearchBarRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged(e);
            if (Control != null)
            {
                if (Focused)
                {
                    ResignFirstResponder();
                }
            }
        }
    }
}

【讨论】:

  • 看起来不错,我去试试。你知道我如何在 Android 中做到这一点吗?谢谢。
猜你喜欢
  • 2023-03-05
  • 1970-01-01
  • 2011-08-26
  • 2020-03-23
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 2013-03-10
  • 2016-09-07
相关资源
最近更新 更多