【问题标题】:how to prevent default keyboard from popping up and enable copy paste option?如何防止弹出默认键盘并启用复制粘贴选项?
【发布时间】:2016-01-28 09:22:41
【问题描述】:

我的应用中有自己的自定义键盘。在 editText 框中,我通过返回 true 禁用了它的 onTouch()

OnTouchListener otl = new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                }
                return true;
            }
        };

这有助于防止键盘弹出。但它也禁用了触摸事件,我没有选择复制粘贴 android 的默认功能。这种情况发生在许多应用程序中,但我没有任何办法去做它。请帮忙。

【问题讨论】:

    标签: android android-keypad


    【解决方案1】:

    您可以将setFocusable 改为false,而不是禁用触摸。这将禁用软键盘弹出。

    editText.setFocusable(false);    
    editText.setFocusableInTouchMode(false);
    

    然后在onTouch,弹出你的自定义键盘

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      实际上在编辑文本 xml 中使用以下一组属性并将可选择的文本设置为 true ,尽管在我的 onTouch() 中返回 false 解决了我的问题。

      <EditText
                  android:id="@+id/numberEditText"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:clickable="true"
                  android:textCursorDrawable="@null"
                  android:ems="10"
                  android:paddingRight="3dip"
                  android:focusable="true"
                  android:focusableInTouchMode="true"
                  android:gravity="center_vertical|end"
                  android:cursorVisible="true"
                  android:background="@drawable/edittext_style_dialer"
                  android:textAppearance="?android:attr/textAppearanceLarge"
                  android:textColorHint="@color/dialer_text_color"
                  android:textSize="@dimen/dialer_text_size" >
      
                  <requestFocus />
              </EditText>
      

      在onCreate()中,

      mNumberInputEditText.setTextIsSelectable(true);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-10
        • 1970-01-01
        • 2013-01-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多