Note that there are some explanatory texts on larger screens.

plurals
  1. POSoftkeyboard not shown when EditText is selected
    primarykey
    data
    text
    <p>I have a Service (implementing TextWatcher) that creates a View at the top of the screen, which only contains an EditText field. This "top bar" is then displayed on top of all activities. At the moment, the EditText is displayed, and TextWatcher methods are called correctly if I set its content programmatically.</p> <p>However the desired behaviour is that, when the EditText is selected, a softkeyboard should pop up from the bottom of the screen but this is not happening, i.e. no keyboard is displayed.</p> <p>I can't figure out why it works with Activities but not with my Service. My gut feeling is that the keyboard wants to be displayed in the same view of the TextWatcher, not sure though.</p> <p>Can anyone please help?</p> <p>This is a snippet of my code:</p> <pre><code>public final class TopBarService extends Service implements TextWatcher, OnFocusChangeListener { protected LayoutInflater mInflater; protected WindowManager mWindowManager; protected View mTopEditBar; protected EditText mTopEditText; public void onCreate() { // Create top bar mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE); mTopBar = mInflater.inflate(R.layout.top_bar, null); mTopEditText = (EditText) mTopBar.findViewById(R.id.top_edit_text); WindowManager.LayoutParams params = ...; // some "standard" params here mWindowManager.addView(mTopBar, params); mTopEditText.addTextChangedListener(this); mTopEditText.setOnFocusChangeListener(this); mTopEditText.setInputType(InputType.TYPE_CLASS_TEXT); mTopEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); } // TextWatcher implementation public void afterTextChanged(Editable s) { //... } public void beforeTextChanged(Editable s) { //... } public void onTextChanged(Editable s) { //... } public void onFocusChange(View v, boolean hasFocus) { // see Edit below } ... } </code></pre> <p>Where res/layout/top_bar.xml is:</p> <pre><code>&lt;EditText android:id="@+id/top_edit_text" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;/EditText&gt; </code></pre> <p>Edit: Little progress.</p> <p>I've noticed that, by using the InputMethodManager, this is not active:</p> <pre><code>public void onFocusChange(View v, boolean hasFocus) { InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.restartInput(mTopEditText); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); imm.showSoftInput(mTopEditText, InputMethodManager.SHOW_IMPLICIT); Log.d(TAG, "active? " + imm.isActive()); // false Log.d(TAG, "activeOnView? " + imm.isActive(mTopEditText)); // false Log.v(TAG, "accepting text? " + imm.isAcceptingText()); // false } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload