Android: InputMethodService how to set a view with setExtractView(View view)?

梦想与她 提交于 2019-12-21 21:22:11

问题


I'm trying to provide a modified view for a custom Android keyboard in fullscreen mode. Therefor I'm trying to replace the extract view. In the documentation I found the following method: setExtractView(View view) - so I assume it's a public API call.

However, as you can see from the Android OS source code (snipped pasted below) it lets me only access a view that has view items with id's within the com.android.internal.* space. Otherwise I will, of course, get a NullPointerException.

public void setExtractView(View view) {
    mExtractFrame.removeAllViews();
    mExtractFrame.addView(view, new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mExtractView = view;
    if (view != null) {
        mExtractEditText = (ExtractEditText)view.findViewById(
                com.android.internal.R.id.inputExtractEditText);
        mExtractEditText.setIME(this);
        mExtractAction = (Button)view.findViewById(
                com.android.internal.R.id.inputExtractAction);
        if (mExtractAction != null) {
            mExtractAccessories = (ViewGroup)view.findViewById(
                    com.android.internal.R.id.inputExtractAccessories);
        }
        startExtractingText(false);
    } else {
        mExtractEditText = null;
        mExtractAccessories = null;
        mExtractAction = null;
    }
}

So, I'm wondering, is it a bug, that this method is within the public API or if not, how can I create a custom view with IDs in the com.android.internal.* space?


Update: Nevermind, just found this. Will check later and report back if it worked.


回答1:


A bit late, but still here the answer (thanks Samuel for pinging me). The solution is actually quite simple:

ExtractEditText extractEditTextView = new ExtractEditText(this);
extractEditTextView.setId(android.R.id.inputExtractEditText);


来源:https://stackoverflow.com/questions/4026631/android-inputmethodservice-how-to-set-a-view-with-setextractviewview-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!