Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable one key on custom keyboard in Android

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"/>
...

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())

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

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.

like image 855
mjollneer Avatar asked Oct 12 '12 12:10

mjollneer


People also ask

Can you disable an individual key on a keyboard?

Select the key that you want to disable. Under the Keyboard Controls section, select Disable Key. Click on Apply.


1 Answers

I am currently using android:horizontalGap to place a black gap (with the width of a key) in the place where the disabled key should be placed (in this way, I can hide keys not allowed in each screen, because my keyboard has always the same distribution). It's a poor workaround, though.

The main problem is for the rightmost keys, since android:horizontalGap can only be set for the left side of a key. But using an android:keyWidth="0" attribute in a rightmost fake key and then setting there the proper android:horizontalGap, does the trick. An even poorer workaround...

Any better solution?

like image 177
thelawnmowerman Avatar answered Oct 10 '22 20:10

thelawnmowerman