简体   繁体   English

如何在 textview android 中显示输入法选择器列表标题和摘要?

[英]How to display input method picker list title and summary in textview android?

i am sing keyboard view to select.我正在向 select 唱键盘视图。 After selecting the keyboard, how to display the selected keyboard text in textview android?选择键盘后,如何在textview android中显示选择的键盘文字?

i can display only language but how to display the Title and summary for change keyboard?我只能显示语言,但如何显示更改键盘的标题和摘要?

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn = findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @RequiresApi(api = Build.VERSION_CODES.N)
            @Override
            public void onClick(View view) {

                InputMethodManager imm = (InputMethodManager) MainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showInputMethodPicker();
                InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
                String localeString = ims.getLocale();
                Locale locale = new Locale(localeString);
                String currentLanguage = locale.getDisplayLanguage();
                Toast.makeText(MainActivity.this,currentLanguage,Toast.LENGTH_SHORT)
                        .show();
               //Title and summary for change keyboard  need to display

            }
        });
    }
}

there are two ways to handle this, the simplest way is use a non-size-edittext有两种方法可以解决这个问题,最简单的方法是使用 non-size-edittext

don't hide the text view, if it hide then edtTxt.getText().toString() gets empty always不要隐藏文本视图,如果它隐藏,那么 edtTxt.getText().toString() 总是为空

<EditText
    android:id="@+id/edtTxt"
    android:layout_width="0px"
    android:layout_height="0px" />

So that user can't see that.这样用户就看不到了。 and on click of button并单击按钮

edtTxt.requestFocus();
edtTxt.setText("");
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

inputMethodManager.toggleSoftInputFromWindow(edtTxt.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED,
            0);

Now edtTxt.getText().toString() giving text.现在edtTxt.getText().toString()给出文本。

Without an EditText you're going to have a hard time.如果没有 EditText,您将很难过。

An InputMethod needs to be connected to a view. InputMethod 需要连接到视图。 Whatever view you use, you need to override onCreateInputConnection to return a custom InputConnection object that at a minimum implements commitText (for word input), deleteSurroundingText (for deletes), and sendKeyEvent (for keyboards that assume you're in dumb mode), and all of the completion functions.无论您使用什么视图,您都需要覆盖 onCreateInputConnection 以返回一个自定义 InputConnection object,它至少实现了 commitText(用于单词输入)、deleteSurroundingText(用于删除)和 sendKeyEvent(用于假设您处于哑模式的键盘),以及所有的完成功能。 Input connections are complicated things and you'll screw up 3rd party keyboards like Swiftkey and Swype if you don't get it right.输入连接是复杂的事情,如果你不正确,你会搞砸 Swiftkey 和 Swype 等 3rd 方键盘。 I really don't suggest doing this.我真的不建议这样做。

If you want to do this your best chance of getting it right is to claim your window is a TYPE_NULL input type.如果你想这样做,最好的机会是声明你的 window 是 TYPE_NULL 输入类型。 Most keyboards will dumb themselves down and assume you only accept the simplest commands in that mode.大多数键盘都会让自己变得笨拙,并假设您在该模式下只接受最简单的命令。 But you can't count on it.但你不能指望它。

I'd look at the InputConnection returned by the EditText class and copy as much of it as possible.我会查看 EditText class 返回的 InputConnection 并尽可能多地复制它。

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

相关问题 Android - 如何在输入时在 TextView 中显示键盘输入 - Android - How to display keyboard input in TextView as it is typed Android - 如何在显示活动时自动显示输​​入法选择器? - Android - How do I display input method picker automaticly whenever activity is shown? 如何在Android TextView中显示\\? - How to display \ in android textview? 如何从EditText获取输入,将其转换为整数并在Android中的TextView上显示? - How to take input from EditText, convert it into integer and display it on TextView in Android? 如何从android的TextView上下文菜单中删除输入法 - How to remove input method from android's TextView context menu 如何在Android TextView中显示来自Firebase的消息列表? - How do I display an list of messages from Firebase in an Android TextView? 如何在Android上更改文件选择器标题的外观? - How to change the appearance of the file picker title on Android? 如何在日期选择器对话框android中更改年份和摘要文本大小 - How to change the year and summary text size in date picker dialog android 如何在Android的工具栏上显示Imageview,textView和Title? - How to show Imageview ,textView and Title on Toolbar in android? Android - 如何在工具栏中将标题(TextView)居中? - Android - How to center a title (TextView) in a toolbar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM