简体   繁体   English

ANDROID:仅在双击时打开虚拟键盘?

[英]ANDROID: Opening virtual keyboard only when doubleclicked?

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?目前,当单击需要手动输入的 TextField 或类似内容时,android 虚拟键盘会自动弹出,有没有办法阻止它并仅在我手动双击 TextField 时进行设置?

Ref: How to stop EditText from gaining focus at Activity startup in Android参考: 如何阻止 EditText 在 Android 的 Activity 启动时获得焦点

<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因此,仅当您按两次时,焦点才会出现在文本视图上

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)
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 仅当在android上打开虚拟键盘时才向上移动文本视图 - move up text view only when virtual keyboard open on android 当在android的edittext字段中选择所有文本时,阻止打开虚拟键盘 - block virtual keyboard from opening when all text selected in edittext field in android KeyEvent.ACTION_UP 仅在我使用计算机键盘时有效,但在 android 虚拟键盘中无效 - KeyEvent.ACTION_UP only works when I use computer keyboard but not works in android virtual keyboard 如何防止虚拟键盘打开 Nativescript (IOS/Android) - How to prevent the virtual keyboard from opening Nativescript (IOS/Android) 打开虚拟键盘时,我的应用程序Web视图没有缩小吗? - My apps web view doesnt shrink when opening virtual keyboard? 打开Android虚拟设备管理器时出错 - Error when opening Android Virtual Device Manager 打开虚拟键盘时,请参阅底部的完整输入布局 - See full input layout on bottom when opening virtual keyboard 在android上打开键盘时的布局问题 - Layout problems when opening the keyboard on android 在Nativescript中获取打开时的Android键盘高度 - Get Android keyboard height when opening it, in Nativescript 更改键盘时,Android虚拟键盘出现两次 - Android virtual keyboard appears twice when changing keyboard
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM