将系统软键盘更换为定制软键盘

发布于 2024-12-01 20:18:49 字数 464 浏览 0 评论 0原文

我在 Android 项目上创建了自己的键盘,并且运行良好;这是一小段代码:

mKeyboard = new Keyboard(this, R.layout .keyboard);
mKeyboardView = (CustomKeyboardView) findViewById(R.id.KeyboardArea);
mKeyboardView.setKeyboard(mKeyboard);

每当用户触摸我的 Activity 的 editText 时,我都会让它出现。我的问题是,如果我按下模拟器键盘的中央按钮,标准键盘仍然可以工作...此外,尽管我将其放在

android:windowSoftInputMode="adjustResize"

我的 AndroidManifest 文件中,但它仅适用于标准键盘...所以,是否可以用我定制的软键盘完全替代系统的软键盘?

I created my own keyboard on my Android Project, and it works fine; here is a little snippet of code:

mKeyboard = new Keyboard(this, R.layout .keyboard);
mKeyboardView = (CustomKeyboardView) findViewById(R.id.KeyboardArea);
mKeyboardView.setKeyboard(mKeyboard);

I make it appear whenever the user touches the editText of my Activity. My problem is that the standard keyboard is still working if I press the central botton of my emulator keyboard...furthermore despite I put this:

android:windowSoftInputMode="adjustResize"

in my AndroidManifest file but it only works for the standard keyboard...so, is it possibile to completely substitute the system's soft keyboard with my customized one?

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

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

发布评论

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

评论(2

顾忌 2024-12-08 20:18:49

尝试: getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

另请参阅:如何停止焦点更改时自动显示软键盘(OnStart 事件)

Try: getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

See also: How to stop Soft keyboard showing automatically when focus is changed (OnStart event)

∞琼窗梦回ˉ 2024-12-08 20:18:49

你只需这样做....

int lastwidth;

@Override
    public void onInitializeInterface() {

        if(mKeyboard!=null){
            int diswidth = getMaxWidth();
            if(lastwidth==diswidth){
                return;
            }
            lastwidth=diswidth;
        }

        alphakeyb = new Keyboard(this, R.layout.alphakey);

    }

    @Override
    public View onCreateInputView() {

        // inflatin keyboardview from xml file
        keybview = (KeyboardView) getLayoutInflater().inflate(R.layout.customkeybview,null);

        // setting listner on keyboardview
        keybview.setOnKeyboardActionListener(this);
        // setting keyboard to keyboardview
        keybview.setKeyboard(alphakeyb);

        return keybview;

    }

你也可以参考 API 演示中的 android 软键盘示例

You just do this....

int lastwidth;

@Override
    public void onInitializeInterface() {

        if(mKeyboard!=null){
            int diswidth = getMaxWidth();
            if(lastwidth==diswidth){
                return;
            }
            lastwidth=diswidth;
        }

        alphakeyb = new Keyboard(this, R.layout.alphakey);

    }

    @Override
    public View onCreateInputView() {

        // inflatin keyboardview from xml file
        keybview = (KeyboardView) getLayoutInflater().inflate(R.layout.customkeybview,null);

        // setting listner on keyboardview
        keybview.setOnKeyboardActionListener(this);
        // setting keyboard to keyboardview
        keybview.setKeyboard(alphakeyb);

        return keybview;

    }

You can also refer the android softkeyboard example in the API Demos

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文