简体   繁体   English

在应用程序中包含软键盘

[英]Inculding a soft keyboard in an application

For a research project, I'm developing an android chat application.对于一个研究项目,我正在开发一个 android 聊天应用程序。 For this, it is crucial that all users of the application should use the same, modified keyboard.为此,应用程序的所有用户都应该使用相同的修改过的键盘,这一点至关重要。

My question is the following: Is it possible to deliver a soft keyboard like the simple-keyboard ( https://github.com/rkkr/simple-keyboard ) with the application?我的问题如下:是否可以通过应用程序提供像简单键盘( https://github.com/rkkr/simple-keyboard )这样的软键盘? Or alternatively, is it possible to force the user to utilize a certain keyboard for the text input?或者,是否可以强制用户使用某个键盘进行文本输入?

Thanks in advance.提前致谢。

It isn't possible to force a keyboard in a non rooted phone, since there's a security block.不可能在非 root 手机中强制使用键盘,因为有一个安全块。 You can however ask the user to select your keyboard as in Robert's answer :但是,您可以要求用户选择您的键盘,如罗伯特的回答

InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();

And yes, you can add it in your application, you just need to add the keyboard code within your app, take a look a this question to see how to make a keyboard.是的,您可以将它添加到您的应用程序中,您只需要在您的应用程序中添加键盘代码,看看这个问题,看看如何制作键盘。 But the most important part probably is the Manifest, because it is what will make your application show in the input method picker:但最重要的部分可能是 Manifest,因为它将使您的应用程序显示在输入法选择器中:

Code by Suragch : Suragch 的代码:

<manifest ...>
    <application ... >
        <activity ... >
            ...
        </activity>

        <service
            android:name=".MyInputMethodService"
            android:label="Keyboard Display Name"
            android:permission="android.permission.BIND_INPUT_METHOD">
            <intent-filter>
                <action android:name="android.view.InputMethod"/>
            </intent-filter>
            <meta-data
                android:name="android.view.im"
                android:resource="@xml/method"/>
        </service>

    </application>
</manifest>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM