在Android中禁用自定义键盘上的一键

Disable one key on custom keyboard in Android(在Android中禁用自定义键盘上的一键)
本文介绍了在Android中禁用自定义键盘上的一键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我的 Android 应用中有自定义 键盘.xml中描述的布局是这样的

I have custom keyboard in my app for Android. It's layout described in xml like this

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"">
 <Row>
     <Key android:keyLabel="F1" android:keyOutputText="F1"/>
     <Key android:keyLabel="F2" android:keyOutputText="F2"/>
     <Key android:keyLabel="F3" android:keyOutputText="F3"/>
...

所以,我很想知道如何禁用,例如f1"键~让它变灰且不可触摸.这里有一些类似的问题,但都是关于默认软知识库的.

So, i'm insteresting how i can disable, for example 'f1' key ~ make it grey and untouchable. There are some similar questions here, but all about default soft-KB.

我知道我可以像这样遍历键

I know I can iterate through keys like this

for (Keyboard.Key key : myKeyboard.getKeys())

但它看起来像 Keyboard.Key 类的对象对按键外观的任何变化都无用.

but it's look like objects of Keyboard.Key class are useless for any changes in key's look.

UPD:我没有找到解决方案.我手动实现了键盘——大的相对布局、常用按钮和自定义按钮,一切都很好.顺便说一句 - 自定义键盘至少更漂亮.只需从 droid 4+ 复制资源 - 您将在每个平台上获得漂亮的现代透明按钮和透明布局.

UPD: I did not found solution. I implemented keyboard manually - big relative layout, common buttons and custom buttons and everything fine. By the way - custom keyboard at least more beautiful. Just copy resources from droid 4+ - and you'll get nice modern transparent buttons and transparent layout on every platform.

推荐答案

通常键盘只有在编辑时才可见,因此您可以通过对象捕获编辑.如果它是一个 editText 框,那么您可以添加一个侦听器,然后您可以禁用对编辑文本的任何响应.我不确定这是否对您有用,但至少您可以捕获任何不需要的输入.

Usually the keyboard is only visible if you are editing something, so you can trap the edits via the object. If its an editText box then you can add a listener and then you could disable any response to the edit text. I'm not sure if this is useful to you but at least you can trap any unwanted input.

    // add a keylistener to keep track user input
    editText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // if keydown and "enter" is pressed
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {

                // do some thing or nothing

                return true;

            }

            return false;
        }
    });

这篇关于在Android中禁用自定义键盘上的一键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)