[英]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.