Currently, when clicking into TextField or similar where manual input is requred the android virual keyboard pops up automaticaly, is there a way to prevent it and set it only when i manualy double click into the TextField?
Asked
Active
Viewed 90 times
2 Answers
0
Ref: How to stop EditText from gaining focus at Activity startup in Android
<LinearLayout
android:focusable="true" //insert this line in your parent layout
android:focusableInTouchMode="true"//insert this line in your parent layout
android:layout_width="0px"
android:layout_height="0px"/>
<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:nextFocusUp="@id/autotext"
android:nextFocusLeft="@id/autotext"/>
What this does is it makes the parent layout get the focus by deafult. Hence the focus will be present on the text view only if you press it twice

Narendra_Nath
- 4,578
- 3
- 13
- 31
-
I wish to keep focus upon click, but just simply dont open the vitual keyboard – Jiri Zaloudek Apr 16 '21 at 13:00
0
in Activity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_account_setting)
//add for keyboard don't open automatically
this.window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)
// and edit text enable false
edittext.isEnabled = false
editText.setOnClickListener(new View.OnClickListener() {
int count = 0;
Handler handler = new Handler();
Runnable runnable = () -> count = 0;
@Override
public void onClick(View v) {
if (!handler.hasCallbacks(runnable))
handler.postDelayed(runnable, 500);
if(count==2){
edittext.isEnabled = true
showKeyboard(editText, thiscontext!!)
//
}
}
});
//..............
fun showKeyboard(editText: EditText, context: Context) {
editText.post {
editText.requestFocus()
val imm = editText.context
.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT)
}
}

Sandeep Pareek
- 1,636
- 19
- 21
-
as newbie, can you show how/where to implement? any link for similar solution should be enough for me to understand the basics of implementation – Jiri Zaloudek Apr 16 '21 at 13:01