Android: Force EditText to remove focus? [duplicate]
You can make cursor and focus disappear by edittext.clearFocus(); But detect when the key board hide is a hard work.
You can make cursor and focus disappear by edittext.clearFocus(); But detect when the key board hide is a hard work.
Statically (i.e. in your layout XML file): set android:inputType=”textCapSentences” on your EditText. Programmatically: you have to include InputType.TYPE_CLASS_TEXT in the InputType of the EditText, e.g. EditText editor = new EditText(this); editor.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); Can be combined with text and its variations to request capitalization of the first character of every sentence. – Google Docs
By using getText(): Button mButton; EditText mEdit; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mButton = (Button)findViewById(R.id.button); mEdit = (EditText)findViewById(R.id.edittext); mButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { Log.v(“EditText”, mEdit.getText().toString()); } }); }
I am wondering if there is a way to handle the user pressing Enter while typing in an EditText, something like the onSubmit HTML event. Yes. Also wondering if there is a way to manipulate the virtual keyboard in such a way that the “Done” button is labeled something else (for example “Go”) and performs … Read more
To force the soft keyboard to appear, you can use EditText yourEditText= (EditText) findViewById(R.id.yourEditText); yourEditText.requestFocus(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); And for removing the focus on EditText, sadly you need to have a dummy View to grab focus. To close it you can use InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0); This works … Read more
By default all the EditText widgets in Android are multi-lined. Here is some sample code: <EditText android:inputType=”textMultiLine” <!– Multiline input –> android:lines=”8″ <!– Total Lines prior display –> android:minLines=”6″ <!– Minimum lines –> android:gravity=”top|start” <!– Cursor Position –> android:maxLines=”10″ <!– Maximum Lines –> android:layout_height=”wrap_content” <!– Height determined by content –> android:layout_width=”match_parent” <!– Fill entire width … Read more
You can set the EditText to have a custom transparent drawable or just use android:background=”@android:color/transparent” or android:background=”@null” or Programmatically editText.setBackgroundResource(android.R.color.transparent);
Setting the android:textCursorDrawable attribute to @null should result in the use of android:textColor as the cursor color. Attribute “textCursorDrawable” is available in API level 12 and higher
Documentation Example android:maxLength=”10″
Try this: UPDATE: Kotlin: editText.setSelection(editText.length())//placing cursor at the end of the text Java: editText.setSelection(editText.getText().length());