Reputation: 684
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;
}
Upvotes: 9
Views: 3421
Reputation: 777
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.
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;
@Override
public void onComputeInsets(Insets outInsets) {
super.onComputeInsets(outInsets);
if (!isFullscreenMode()) {
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
}
The result will be
Upvotes: 2
Reputation: 1113
I had the same problem. I found the answer on the post by Ced here.
The solution is to add this to your input method service,
@Override public void onComputeInsets(InputMethodService.Insets outInsets) {
super.onComputeInsets(outInsets);
if (!isFullscreenMode()) {
outInsets.contentTopInsets = outInsets.visibleTopInsets;
}
}
It is intentional that the candidate view does not push the application upwards. From the doc,
Note that because the candidate view tends to be shown and hidden a lot, it does not impact the application UI in the same way as the soft input view: it will never cause application windows to resize, only cause them to be panned if needed for the user to see the current focus.
The hack above increases the "content" area to include the candidate view area. The doc for onComputeInsets
will help you understand the concept.
Compute the interesting insets into your UI. The default implementation uses the top of the candidates frame for the visible insets, and the top of the input frame for the content insets.
Upvotes: 14