OS 4.5(或更高版本)兼容代码上的 BlackBerry 软件键盘侦听器

发布于 2024-11-14 18:48:20 字数 389 浏览 7 评论 0原文

我正在开发一个应用程序,该应用程序应该在操作系统 4.5 或更高版本的设备上运行。在我的应用程序中,我需要知道虚拟键盘何时可见或不可见。因为如果虚拟键盘可见,则用户应该输入的文本区域位于键盘后面。如果我可以确定虚拟键盘状态更改的时刻,我可以刷新屏幕并将文本区域移动到上方位置。

有办法做到这一点吗?

编辑:下一个按钮位于状态面板上。编辑字段位于自定义水平字段管理器处。

在此处输入图像描述

当我触摸编辑字段时,虚拟键盘打开,编辑字段的内容丢失。

在此处输入图像描述

I am developing an app which supposed to work on devices that have OS 4.5 or later. In my application I need to know when the virtual keyboard is visible or invisible. Because if virtual keyboard is visible, the text area which the user is supposed to type in is behind the keyboard. If I could determine the moment of virtual keyboards state changed, I could refresh the screen and move the text area upper location.

Is there a way to do that?

Edit: the next button is at the status panel. The edit field is at the custom horizontal field manager.

enter image description here

When I touch the edit field, the virtual keyboard opens and the contents of the edit field is lost.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

┼── 2024-11-21 18:48:20

没有办法用相同的代码来做到这一点。您需要将代码分成两部分。其中一台可处理 4.5 - 4.7。另一个处理 4.7 及更高版本。

您可以将键盘侦听器添加到 4.7(及更高版本)代码中,以检查屏幕是否在连续线程中发生变化。这不好,但是可以工作。

There is no way to do that with the same code. You need to divide your code in two. One of them handles 4.5 - 4.7. The other handles 4.7 and later.

You can add a keyboard listener to 4.7 (and later) code that should check whether the screen changes in a continuous thread. It is not good, but it can work.

笑叹一世浮沉 2024-11-21 18:48:20

你有两个选择。第一个选择更好:

  • 找出一个适用于可见或隐藏键盘的不变量。当键盘的可见状态发生变化时,调用屏幕布局方法,并且对于可见键盘,垂直尺寸会减小。如果您的不变量利用了这一点,那么您只需在屏幕布局方法中实现逻辑即可。
    在这种情况下,我建议采用一种布局方法,始终将“下一步”按钮保留在屏幕底部,并将用户名文本框放在剩余空间的中心。

  • 使用条件编译,以便您可以编写引用 OS 4.7+ 上的 VirtualKeyboard 类的代码,并且该代码在旧版 BlackBerry 版本中消失。 7 月 4 日:通过条件编译,我的意思是使用 BlackBerry 预处理器。

You have two choices. The first choice is better:

  • Figure out an invariant that works with the keyboard visible or hidden. The screen layout method is invoked when the visibility state of the keyboard changes, and the vertical size is reduced for a visible keyboard. If your invariants take advantage of that then you can just implement the logic in the screen layout method.
    In this case, I would suggest a layout method that always keeps the 'next' button at the bottom of the screen, and puts the username textbox in the center of the remaining space.

  • Use conditional compilation so you can write code that makes reference to the VirtualKeyboard class on OS 4.7+, and that code goes away in the older BlackBerry releases. 4 July: by conditional compilation, I mean use the BlackBerry preprocessor.

沦落红尘 2024-11-21 18:48:20

没有与此相关的事件,但您可以确定虚拟键盘的当前状态并设置所需的状态。
例如隐藏它

    if(VirtualKeyboard.isSupported() == true){
        VirtualKeyboard keyboard = getVirtualKeyboard();

        if(keyboard != null)
            keyboard.setVisibility(VirtualKeyboard.HIDE);
    }

There is no event for this, but you can determine current state of virtual keyboard and set required state.
For example hide it

    if(VirtualKeyboard.isSupported() == true){
        VirtualKeyboard keyboard = getVirtualKeyboard();

        if(keyboard != null)
            keyboard.setVisibility(VirtualKeyboard.HIDE);
    }
素年丶 2024-11-21 18:48:20

这是一项相当具有挑战性的工作。但是,我相信没有直接的 API 或方法来确定虚拟键盘状态。唯一的方法是重写 setLayout() 方法并确定屏幕宽度和高度是否已更改。您还需要检查屏幕的 GUI 布局。

It is a quite challenging job. However, I believe there is no direct API or way to determine the virtual Keyboard state. The only way is to override the setLayout() method and determine if the screen width and height has been changed. And also you need to check the GUI layouts of your screen.

阪姬 2024-11-21 18:48:20

为包含 EditField 的管理器设置 VERTICAL_SCROLL 样式,或者您可以使用具有 VERTICAL_SCROLL 样式的屏幕。执行此操作后,EditField 将在显示键盘时自动滚动。

使用以下课程,也许这对您有帮助:

class FocusableManager extends MainScreen implements FocusChangeListener
{
    private BasicEditField b;
    public FocusableManager() 
    {
        VerticalFieldManager vfm=new VerticalFieldManager(VERTICAL_SCROLL);
        vfm.add(new ButtonField("first"));
        b=new BasicEditField();
        b.setFocusListener(this);
        vfm.add(b);
        vfm.add(new ButtonField("second"));
        vfm.setMargin(250,0,0,0);
        add(vfm);
    }
    public void focusChanged(Field field, int eventType)
    {
        if(field==b)
        {
            if(eventType==1)//when edit field gain focus
            {
                VirtualKeyboard virtKbd;
                virtKbd =  getScreen().getVirtualKeyboard();
                virtKbd.setVisibility(VirtualKeyboard.SHOW_FORCE);
            }
            else if(eventType==3)//when edit field lost focus
            {
                VirtualKeyboard virtKbd;
                virtKbd =  getScreen().getVirtualKeyboard();
                virtKbd.setVisibility(VirtualKeyboard.HIDE_FORCE);
            }
        }
    }
}

Set the VERTICAL_SCROLL style for the Manager which holds the EditField, or you can use a Screen with VERTICAL_SCROLL style. Doing this, the EditField automatically scrolls when the keyboard is displayed.

Use following class, maybe this is helpful for you:

class FocusableManager extends MainScreen implements FocusChangeListener
{
    private BasicEditField b;
    public FocusableManager() 
    {
        VerticalFieldManager vfm=new VerticalFieldManager(VERTICAL_SCROLL);
        vfm.add(new ButtonField("first"));
        b=new BasicEditField();
        b.setFocusListener(this);
        vfm.add(b);
        vfm.add(new ButtonField("second"));
        vfm.setMargin(250,0,0,0);
        add(vfm);
    }
    public void focusChanged(Field field, int eventType)
    {
        if(field==b)
        {
            if(eventType==1)//when edit field gain focus
            {
                VirtualKeyboard virtKbd;
                virtKbd =  getScreen().getVirtualKeyboard();
                virtKbd.setVisibility(VirtualKeyboard.SHOW_FORCE);
            }
            else if(eventType==3)//when edit field lost focus
            {
                VirtualKeyboard virtKbd;
                virtKbd =  getScreen().getVirtualKeyboard();
                virtKbd.setVisibility(VirtualKeyboard.HIDE_FORCE);
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文