Owen Ryan
Owen Ryan

Reputation: 266

Making a Virtual Keyboard scrollable in android

I've successfully created an IMS(InputMangerService) virtual keyboard and now I want to make it scroll-able, like the google emoji keyboard.

It is possible using candidate views at least, and google have pulled it off with their own emoji keyboard.

But I have no idea how to do it. Any ideas?

Edit 1: Further testing and research has yielded no results. In fact, the only example of scrollable keyboards I can find are google's own candidate view and one example which was made using a dialog view in an activity rather than with an softkeyboard.

So my new question is: Is it even possible to create a scrollable virtual Keyboard?

Upvotes: 2

Views: 550

Answers (1)

Owen Ryan
Owen Ryan

Reputation: 266

I found a solution:

You need to create a virtual keyboard with no buttons or rows, then set that keyboard's candidate view to a new scrollview, then show the Candidate View. From there you can add views to the scrollview programically to create the keyboard you want.

public class MyKeyboardService extends InputMethodService implements KeyboardView.OnKeyboardActionListener
{
    private KeyboardView viewOfKeyboard;
    private Keyboard theKeyboardLayout;
    private HorizontalScrollView scrollingKeyboard;


    @Override
    public View onCreateInputView()
    {
       viewOfKeyboard =  keyboardView)getLayoutInflater().inflate(R.layout.keyboard1, null);
       theKeyboardLayout = new Keyboard(this, R.xml.keyboardlayout);
       //keyboardlayout.xml contains no rows or keys.
       viewOfKeyboard.setKeyboard(theKeyboardLayout);


       setCandidatesViewShown(true);
       //Sets the candidate view to be always shown.
       return viewOfKeyboard;
    }

    public View onCreateCandidatesView()
    {
       scrollingKeyboard = new HorizontalScrollView(this);
       scrollingKeyboard.addView(new Button(this));
       return scrollingKeyboard;
    }
}

Upvotes: 2

Related Questions