Change keyboard language programmatically

后端 未结 2 1410
野性不改
野性不改 2020-12-02 01:37

In my application the user selects a language and I want to show the selected language when the keyboard opens (if it is present in the keyboard options). The keyboard provi

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 01:44

    this code is working fine

    public class ParisaKeyboard extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
    
    public KeyboardView kv;
    private Keyboard keyboard;
    private Keyboard persianKeyboard;
    
    @Override
    public View onCreateInputView() {
    
        kv = (KeyboardView)getLayoutInflater().inflate(R.layout.keyboard,null);
    
        keyboard = new Keyboard(this, R.xml.qwerty);
        persianKeyboard = new Keyboard(this, R.xml.persian);
    
        kv.setKeyboard(keyboard);
        kv.setOnKeyboardActionListener(this);
        return kv;
    }
    
    @Override
    public void swipeLeft() {
    
        kv.setKeyboard(persianKeyboard);
    }
    
    @Override
    public void swipeRight() {
        kv.setKeyboard(keyboard);
    }
    

    so you can change language by swiping to left and right .

提交回复
热议问题