1

I need to create a custom keyboard containing numbers only.
But all the tutorials I found are about regular keyboards (qwerty).

I need a layout like this, but I don't know where to even start with it.

enter image description here

Note, that just using the numbers or phone input method for my editTexts won't do.

keinabel
  • 1,002
  • 3
  • 15
  • 33
  • 1
    Or you can just make your own buttons and layout below the PIN edit text with the numbers. – HendraWD Dec 05 '16 at 16:02
  • 2
    "Note, that just using the numbers or phone input method for my editTexts won't do" -- creating a custom input method editor will not help you, then, as the user does not have to use your custom input method editor when typing into your `EditText` widgets. It sounds like this should not be an `EditText` at all, but, as HendraWD suggests, just a set of buttons, which you use to populate a `TextView` as visual feedback. – CommonsWare Dec 05 '16 at 16:03
  • 1
    http://stackoverflow.com/a/21873135/3887432 – Mithun Sarker Shuvro Dec 05 '16 at 16:08
  • @shuvro I tried that, but it didn't work for unknown reasons – keinabel Dec 05 '16 at 16:14
  • @bigdestroyer I did, but there are only tutorials for qwerty keyboards. And I think I need some way to use GridLayout to achieve this kind of keyboard. – keinabel Dec 05 '16 at 16:15

2 Answers2

1

I did it basically like in this tutorial:

https://code.tutsplus.com/tutorials/create-a-custom-keyboard-on-android--cms-22615

But replaced the qwerty.xml code with this

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="23.4375%p"
android:keyHeight="10%p" >

<Row>
    <Key android:codes="49"    android:keyLabel="1"  android:keyEdgeFlags="left" />
    <Key android:codes="50"    android:keyLabel="2" />
    <Key android:codes="51"    android:keyLabel="3" />
    <Key android:codes="-5"     android:keyLabel="Del" android:isRepeatable="true" android:horizontalGap="6.25%p" android:keyEdgeFlags="right"/>
</Row>
<Row>
    <Key android:codes="52"    android:keyLabel="4" android:keyEdgeFlags="left"  />
    <Key android:codes="53"    android:keyLabel="5" />
    <Key android:codes="54"    android:keyLabel="6" android:keyEdgeFlags="right"/>
</Row>
<Row>
    <Key android:codes="55"    android:keyLabel="7" android:keyEdgeFlags="left" />
    <Key android:codes="56"    android:keyLabel="8" />
    <Key android:codes="57"    android:keyLabel="9" android:keyEdgeFlags="right"/>
    <Key android:codes="-2"  android:keyLabel="123" android:horizontalGap="6.25%p"/>
</Row>
<Row>
    <Key android:codes="0"  android:keyLabel="ABC" android:keyEdgeFlags="left" />
    <Key android:codes="46"    android:keyLabel="."/>
    <Key android:codes="48"    android:keyLabel="0" />
    <Key android:codes="10" android:keyLabel="Ent" android:horizontalGap="6.25%p" android:keyEdgeFlags="right" />
</Row>

123 and ABC is just navigating between other keyboards. Delete them if not needed.

Mika
  • 41
  • 5
0

I now went for using no keyboard and using GridLayout instead.

<GridLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentStart="true"
    android:layout_gravity="center"
    android:columnCount="3"
    android:orientation="horizontal"
    android:weightSum="3">

    <Button
        android:layout_columnWeight="1"
        android:text="1" />

    <Button
        android:layout_columnWeight="1"
        android:text="2" />

    <Button
        android:layout_columnWeight="1"
        android:text="3" />

    <Button
        android:layout_columnWeight="1"
        android:text="4" />

    <Button
        android:layout_columnWeight="1"
        android:text="5" />

    <Button
        android:layout_columnWeight="1"
        android:text="6" />

    <Button
        android:layout_columnWeight="1"
        android:text="7" />

    <Button
        android:layout_columnWeight="1"
        android:text="8" />

    <Button
        android:layout_columnWeight="1"
        android:text="9" />

    <Button
        android:layout_columnWeight="1"
        android:layout_column="1"
        android:text="0" />
</GridLayout>
keinabel
  • 1,002
  • 3
  • 15
  • 33