android - 如何禁用长按android的键盘

标签 android android-layout

我使用了一个文本框来查看从字符串文件中获取的文本。如果用户愿意,我想给从编辑文本复制文本的机会。可以全部复制,也可以部分复制。

当长按事件发生时,复制信息出来。但虚拟键盘也出来了。 我无法隐藏它。 我尝试了几种方法,这是我的 xml 代码。

<EditText
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginBottom="23dp"
    android:background="@null"
    android:editable="false"
    android:gravity="right"
    android:inputType="none"
    android:padding="@dimen/padding_maintextview"
    android:text="@string/text"
    android:textAppearance="?android:attr/textAppearanceMedium" />

这是Java代码。

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(tvchange12.getWindowToken(), 0);
tvchange12.onCheckIsTextEditor();

这是 MEdit 类

public class MEditText extends EditText {
    public MEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    @Override
    public boolean onCheckIsTextEditor() {
        return false;
    }
}

请帮我隐藏长按的虚拟键盘。

最佳答案

如果您不需要编辑文本,请改用 TextView,这样用户无需键盘即可选择和复制文本

关于android - 如何禁用长按android的键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13561643/

相关文章:

android - android widget 背景应该是九色补丁吗?应该有不同的 dpi 版本吗?

android - RelativeLayout 支持多种屏幕尺寸

java - 动态设置滑动抽屉高度

android - 约束布局获取 ImageView 的默认上边距

android - "This app won' t 运行,除非您更新 google play 服务"警报

android - 操作栏中的进度条不可点击

android - 如何去掉应用程序顶部的程序名称栏?

android - 强制布局为一定高度

android - 为 Samsung Galaxy s2 和 Galaxy s3 开发应用程序时应该使用什么模拟器分辨率?

android - android.intent.action.MAIN 是什么意思?