How to change background color or theme of keys dynamically in Custom Keyboard Android
Date : March 29 2020, 07:55 AM
I wish this helpful for you Get solution to change the layout of custom keyboard. When keyboard first time load onCreateInputView() is called. After that when keyboard open onStartInputView(EditorInfo attribute, boolean restarting) called every time. public KeyboardView mInputView;
public View onCreateInputView() {
SharedPreferences pre = getSharedPreferences("test", 1);
int theme = pre.getInt("theme", 1);
if(theme == 1)
{
this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input, null);
}else
{
this.mInputView = (KeyboardView) this.getLayoutInflater().inflate(R.layout.input_2, null);
}
this.mInputView.setOnKeyboardActionListener(this);
this.mInputView.setKeyboard(this.mQwertyKeyboard);
return this.mInputView;
}
public void onStartInputView(EditorInfo attribute, boolean restarting) {
super.onStartInputView(attribute, restarting);
setInputView(onCreateInputView());
}
|
How to set different background of keys for Android Custom Keyboard
Date : March 29 2020, 07:55 AM
Hope that helps As an example, there's a small downloadable project that creates a custom numeric keyboard. To the CustomKeyboardView class there or to your own custom keyboard class, add a method like the following. It overrides the onDraw() method and draws the background of the key defined with code 7 (in this case the "0") red and all the other keys blue. @Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
List<Key> keys = getKeyboard().getKeys();
for (Key key : keys) {
if (key.codes[0] == 7) {
Log.e("KEY", "Drawing key with code " + key.codes[0]);
Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.red_tint);
dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
dr.draw(canvas);
} else {
Drawable dr = (Drawable) context.getResources().getDrawable(R.drawable.blue_tint);
dr.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
dr.draw(canvas);
}
}
}
@Override
public void onDraw(Canvas canvas) {
// super.onDraw(canvas);
List<Key> keys = getKeyboard().getKeys();
for (Key key : keys) {
if (key.codes[0] == 7) {
NinePatchDrawable npd
= (NinePatchDrawable) context.getResources().getDrawable(R.drawable.red_key);
npd.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
npd.draw(canvas);
} else {
NinePatchDrawable npd
= (NinePatchDrawable) context.getResources().getDrawable(R.drawable.blue_key);
npd.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
npd.draw(canvas);
}
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.CENTER);
paint.setTextSize(48);
paint.setColor(Color.GRAY);
if (key.label != null) {
canvas.drawText(key.label.toString(), key.x + (key.width / 2),
key.y + (key.height / 2), paint);
} else {
key.icon.setBounds(key.x, key.y, key.x + key.width, key.y + key.height);
key.icon.draw(canvas);
}
}
}
|
Android Custom Keyboard Change Background color key pressed
Date : March 29 2020, 07:55 AM
This might help you The problem is with your state list in keybackground.xml. Here is excerpt from state list documentation:
|
Xamarin Forms. Keyboard on android covers bottom of an entry with custom background
Date : March 29 2020, 07:55 AM
may help you . I fixed it. The problem was with padding for entry. It was 0 for bottom and top. I set it as shown in following code: private void UpdatePadding(MessageEntry MessageEntry)
{
Control.SetPadding((int)Forms.Context.ToPixels(MessageEntry.LeftPadding), Control.PaddingTop/3,
(int)Forms.Context.ToPixels(MessageEntry.RightPadding), Control.PaddingTop/3);
}
|
In Android Custom Keyboard, how to change Alphabets Keyboard to Symbols Keyboard?
Date : March 29 2020, 07:55 AM
Any of those help Keyboard Layout draws every key based on the percentage not in dp. So declare your key width as %p not in dp In Layout file <Row
android:horizontalGap="@fraction/key_horizontal_ten_keys_gap"
android:keyWidth="@fraction/ten_keys_key_width"
android:rowEdgeFlags="top">
</Row>
<fraction name="ten_keys_key_width">8.8%p</fraction>
|