Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

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

i am sing keyboard view to select. After selecting the keyboard, how to display the selected keyboard text in 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

            }
        });
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

there are two ways to handle this, the simplest way is use a non-size-edittext

don't hide the text view, if it hide then edtTxt.getText().toString() gets empty always

<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.

Without an EditText you're going to have a hard time.

An InputMethod needs to be connected to a view. 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. Input connections are complicated things and you'll screw up 3rd party keyboards like Swiftkey and Swype if you don't get it right. 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. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.6k users

...