Number Keyboard
Android library that provides a number keyboard view.
Usage
Step 1
Add the JitPack repository to your build.gradle
file:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2
Add the dependency:
dependencies {
compile 'com.github.davidmigloz:number-keyboard:3.1.0'
}
Step 3
Use NumberKeyboard
view in your layout:
<com.davidmiguel.numberkeyboard.NumberKeyboard
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:keyboard="http://schemas.android.com/apk/res-auto"
...
keyboard:numberkeyboard_keyboardType="integer"
... />
Attributes
keyboard:numberkeyboard_keyboardType="[integer|decimal|fingerprint|custom]"
(required): defines the type of keyboard.integer
: numbers and backspace keys.decimal
: numbers, comma and backspace keys.fingerprint
: numbers, fingerprint and backspace keys.custom
: numbers and defined auxiliary keys.
keyboard:numberkeyboard_keyWidth="[dimension]"
(default:match_parent
): key width (wrap_content
not allowed).keyboard:numberkeyboard_keyHeight="[dimension]"
(default:match_parent
): key height (wrap_content
not allowed).keyboard:numberkeyboard_keyPadding="[dimension]"
(default:16dp
): key padding.keyboard:numberkeyboard_numberKeyBackground="[reference]"
(default: circle): number keys background drawable.keyboard:numberkeyboard_numberKeyTextColor="[reference]"
(default: dark blue): number keys text color.keyboard:numberkeyboard_numberKeyTypeface="[reference]"
(default: dark blue): number keys text color.keyboard:numberkeyboard_numberKeyTypeface="[reference]"
(default: none): number keys text typeface.keyboard:numberkeyboard_numberKeyTextSize="[dimension]"
(default: none): number keys text size (if it is not set, the text auto scales to fit the key).keyboard:numberkeyboard_leftAuxBtnBackground="[reference]"
(default: none): ifkeyboardType="custom"
, left auxiliary button background.keyboard:numberkeyboard_rightAuxBtnIcon="[reference]"
(default: none): ifkeyboardType="custom"
, icon shown in right auxiliary button.keyboard:numberkeyboard_rightAuxBtnBackground="[reference]"
(default: none): ifkeyboardType="custom"
, right auxiliary button background.
Methods
hideLeftAuxButton()
: hides left auxiliary button.showLeftAuxButton()
: shows left auxiliary button.hideRightAuxButton()
: hides right auxiliary button.showRightAuxButton()
: shows right auxiliary button.setKeyWidth()
: sets key width in px.setKeyHeight()
: sets key height in px.setKeyPadding()
: sets key padding in px.setNumberKeyBackground()
: sets number keys background.setNumberKeyTextColor()
: sets number keys text color.setNumberKeyTypeface()
: sets number keys text typeface.setNumberKeyTextSize()
: sets number keys text size in pixels.setLeftAuxButtonIcon()
: sets left auxiliary button icon.setRightAuxButtonIcon()
: sets right auxiliary button icon.setLeftAuxButtonBackground()
: sets left auxiliary button background.setRightAuxButtonBackground()
: sets right auxiliary button background.
Callback
To listen to keyboard events, you have to use NumberKeyboardListener
:
onNumberClicked()
: invoked when a number key is clicked.onLeftAuxButtonClicked()
: invoked when the left auxiliary button is clicked.onRightAuxButtonClicked()
: invoked when the right auxiliary button is clicked.
numberKeyboard.setListener(new NumberKeyboardListener() {
@Override
public void onNumberClicked(int number) {...}
@Override
public void onLeftAuxButtonClicked() {...}
@Override
public void onRightAuxButtonClicked() {...}
});
Take a look at the sample app to see the library working.
Contributing
If you find any issues or you have any questions, ideas... feel free to open an issue. Pull request are very appreciated.
License
Copyright (c) 2018 David Miguel Lozano
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.