Rejusting UI with candidateview visible in custom keyboard

Viewed 2874

I'm working on custome keyboard .I have set setCandidatesViewShown(true) function in onCreateCandidatesView() , problem is the UI doesnt get readjusted properly.

Any assistance would be greatful.. below is what I have done

@Override 
public View onCreateCandidatesView() {      

    LayoutInflater li = (LayoutInflater) getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View wordBar = li.inflate(R.layout.wordbar, null);
    LinearLayout ll = (LinearLayout) wordBar.findViewById(R.id.words);
    Button voiceCmd = (Button) wordBar.findViewById(R.id.voiceword);
    LinearLayout ll1 = null;
    Button voiceCmd1 = null;
    //comment this block in the event of showing only one keyboard so that we can only
    //one autocorrect bar
    if (isLargeScreen) {
        ll1 = (LinearLayout) wordBar.findViewById(R.id.words1);
        voiceCmd1 = (Button) wordBar.findViewById(R.id.voiceword1);
    }

    voiceCmd.setOnClickListener(voiceClickListener);

    mCandidateView = new CandidateView(this);
    mCandidateView.setService(this);
    setCandidatesViewShown(true);
    mCandidateView.setLayoutParams(new LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

    ll.addView(mCandidateView);             

    return wordBar;

}
2 Answers

I was facing the same issue. The problem was that when we add CandidateView it does not adjust the ui. Instead of adjusting it overlaps on the edit text.

Like this: enter image description here

Simple Solution

The Class that is inherited with InputMethodService has a method onComputeInsets. Just override the function and check whether the screen is full covered or not. If the screen is not in fullScreenMode(); then add this line to it. It will adjust screen up from candidateView.

outInsets.contentTopInsets = outInsets.visibleTopInsets;

Just like This

 @Override
public void onComputeInsets(Insets outInsets) {
    super.onComputeInsets(outInsets);
    if (!isFullscreenMode()) {
        outInsets.contentTopInsets = outInsets.visibleTopInsets;
    }
}

The result will be

enter image description here

Related