Disable the EditText input method, but keep the cursor blinking

In my Android application, I want an EditText with android:editable="false" , but the cursor is blinking. The blinking cursor does not seem to work after the "editable" parameter is set to false.

I just want to use my own keyboard widget (not the system keyboard) and keep the cursor blinking.

Is there any idea to make this possible?

+4
source share
4 answers

Perhaps try to completely eliminate the xml attribute android:editable , and then try the following in conjunction with

keep the cursor blinking and to prevent touch events from the built-in IME (keyboard).

 /*customized edittext class * for being typed in by private-to-your-app custom keyboard. * borrowed from poster at http://stackoverflow.com/questions/4131448/android-how-to-turn-off-ime-for-an-edittext */ public class EditTextEx extends EditText { public EditTextEx(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onCheckIsTextEditor() { return false; //for some reason False leads to cursor never blinking or being visible even if setCursorVisible(true) was called in code. } } 

Step 2 modify the above method to say return true;

Step 3 Add another method to the class above.

 @Override public boolean isTextSelectable(){ return true; } 

Step 4 In another place where an instance of this class was created and called viewB , I added a new touch event handler

  viewB.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { viewB.setCursorVisible(true); return false; } }); 

Step 5 Verify that the XML instance code and / or EditText declares the IME / keyboard type to "none". I did not confirm relevance, but Im also used the attributes below.

 <questionably.maybe.too.longofa.packagename.EditTextEx android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:focusable="true" android:focusableInTouchMode="true" android:inputType="none"> 

Sorry for so many xml attributes. My code uses them all, testing in 4.2.1 and has results.

Hope this helps.

+4
source

You can use either the xml attribute

Android: cursorVisible = "false"

or java function

setCursorVisible (false).

he will work

0
source

Just add this method for those who are looking and responding. I tried many methods, but only one of them worked from me.

  public static void disableSoftKeyboard(final EditText v) { if (Build.VERSION.SDK_INT >= 11) { v.setRawInputType(InputType.TYPE_CLASS_TEXT); v.setTextIsSelectable(true); } else { v.setRawInputType(InputType.TYPE_NULL); v.setFocusable(true); } } 
0
source

I called the following from onCreate (), but this affects all EditTexts.

 private void hideKeyboard () { getWindow ().setSoftInputMode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); getWindow ().setFlags (WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); } 
0
source

Source: https://habr.com/ru/post/1439518/


All Articles