如何防止默认键盘弹出并启用复制粘贴选项?

时间:2016-01-28 09:22:42

标签: android android-keypad

我的应用中有自己的自定义键盘。在editText框中,我通过返回true

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

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

2 个答案:

答案 0 :(得分:0)

您可以setFocusablefalse,而不是禁用触摸。这将禁用软键盘弹出。

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

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

希望这有帮助。

答案 1 :(得分:0)

实际上在编辑文本xml中使用以下属性集并将selectable中的文本设置为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);