How can I add one extra row of key to the default

2019-03-31 12:14发布

问题:

I have been messing around with custom keyboards but cannot achieve what I want.

I tried to follow various tutorials (like this one How can I implement special soft keyboard) but could not build my own keyboard since there is always missing some part.

I also tried the sample SoftKeyboard that comes with the API 10 samples but the layout did not suit my app.

Now, all I want to have is a the default android 4.3 softkeyboard, that instead of giving the option to switch to the numeric view in the bottom left corner (I am referring to the ?123button) , adds another row of keys to the top. That row should hold the keys '0' to '9'.

Can someone help me out here? I would really appreciate it!

回答1:

Adding extra row to the android default keyboard is not possible for this you have to go to the custom keyboard..Custom keyboard is not much difficult to understand here is the best example of android custom keyboards..

1.Custom keyboard example-1

2.Custom keyboard example-2

Once go to the xml file in the res/xml folder and define keys whatever you want..and no of rows and columns for keyboard..

In your layout definig the keyboardview set android:keyBackground="@drawable/keyboardview_selector" color whatever you want..

 <android.inputmethodservice.KeyboardView
            android:id="@+id/keyboardview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="10dp"
            android:background="@android:color/transparent"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:keyBackground="@drawable/keyboardview_selector" />