小编zen*_*ttu的帖子

Android:如何永久和完全不显示EditText的默认软键盘?

我在一个活动中有三个EditText框,其中两个正常输入方法(硬键,默认软键盘)都可以.但是对于其中一个EditText框,我只想从自定义键盘视图发送软输入.所以实际上我希望永远不会为这个EditText显示默认的软键盘.我尝试为EditText添加onTouchListeners和onFocusChange侦听器,部分成功如下:

public boolean onTouch(View v, MotionEvent event) {
    v.requestFocus();
    imm.toggleSoftInput(0, 0);
    return true;
}

public void onFocusChange(View v, boolean hasFocus) {
    InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
    if (imm.isActive(v)) {
        imm.toggleSoftInput(0,0);
    }
}
Run Code Online (Sandbox Code Playgroud)

但我还没有找到明确的解决方案,因为

1)默认软键盘在听众隐藏之前总是短暂闪烁

2)在某些情况下,例如使用硬键盘箭头键将焦点移动到EditText有时会将默认软键盘设置为可见

等等.

所以我很想找到一种简单的方法来告诉Android永远不要为这个特定的EditText显示默认的软键盘.我不想扩展EditText并开始覆盖东西,因为EditText功能对我来说是完美的 - 我只是希望不显示默认的软键盘.

我花了几天时间试图解决这个问题.通过谷歌找到的一些主题(包括一些在这里)有一半尝试这个问题,但到目前为止,我还没有找到一个完全功能的解决方案.

编辑:

我真的开始生气了.我决定不尝试使用EditText,而是使用其他任何可以完成工作的视图.事实证明,摆脱那个软键盘是很难的.当我使用硬键将焦点从EditText移动到Button时,它甚至出现!为什么软键盘应该显示在碰巧有焦点的每个怪物视图上?即使我明确说inputType ="none"?如何关闭*软键盘?下面是Button的xml - 让我们以此为例:

<Button
    android:id="@+id/OkButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="none"
    android:paddingRight="5mm"
    android:paddingLeft="5mm"
    android:layout_below="@id/Volume"
    android:layout_alignParentLeft="true"
    android:text="OK"/>
Run Code Online (Sandbox Code Playgroud)

EDIT2:

我是如何实现一个似乎有效的解决方案.首先,我得到了InputMethodManager:

this.imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
Run Code Online (Sandbox Code Playgroud)

我设置OnClickListener,OnTouchListener和OnFocusChange监听器,当我想要聚焦EditText并且我的自定义KeyboardView可见时,所有人都调用以下方法,同时隐藏默认的软输入:

private boolean makeActive(View v) {
    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    EditText e = (EditText) v;
    int iType = e.getInputType();
    e.setInputType(InputType.TYPE_NULL); …
Run Code Online (Sandbox Code Playgroud)

java android

6
推荐指数
1
解决办法
3291
查看次数

Android ListView Edge Fading适用于2.2虚拟设备,但不适用于Samsung 2.2.1

在我的ListActivity上,当在Android 2.2虚拟设备上运行时,我得到了淡化边缘效果.但是,当我使用三星GIO与Android 2.2.1运行完全相同的应用程序时,我没有得到ListView边缘淡入淡出.可能是什么原因?下面是ListActivity中ListView的XML:

<ListView
    android:id="@+id/@android:list"
    android:fadingEdge="vertical"
    android:fadingEdgeLength="3mm"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/showMixHeader"/>
Run Code Online (Sandbox Code Playgroud)

android listview listactivity fading

4
推荐指数
1
解决办法
1665
查看次数

标签 统计

android ×2

fading ×1

java ×1

listactivity ×1

listview ×1