Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 软键盘的键盘标签,用于更改键盘文本的文本大小和字体_Android_Android Softkeyboard_Android Fonts - Fatal编程技术网

Android 软键盘的键盘标签,用于更改键盘文本的文本大小和字体

Android 软键盘的键盘标签,用于更改键盘文本的文本大小和字体,android,android-softkeyboard,android-fonts,Android,Android Softkeyboard,Android Fonts,我想定制软键盘。我想更改keylabel的keytext的文本大小和字体。我尝试了很多方法,但键盘没有改变。您可以实现一个,然后您可以定制键盘设计中的几乎所有内容 要更改de文本大小,可以设置属性 不幸的是,这不是更改xml中字体样式的方法,您需要通过编程方式从KeyboardView扩展类。在这种情况下,我建议: 在这里,您可以看到另一个类似的问题: 最后,您可以像我一样完全定制xml布局 public class MyKeyboardView extends KeyboardView { @

我想定制软键盘。我想更改keylabel的keytext的文本大小和字体。我尝试了很多方法,但键盘没有改变。

您可以实现一个,然后您可以定制键盘设计中的几乎所有内容

要更改de文本大小,可以设置属性

不幸的是,这不是更改xml中字体样式的方法,您需要通过编程方式从KeyboardView扩展类。在这种情况下,我建议:

在这里,您可以看到另一个类似的问题:

最后,您可以像我一样完全定制xml布局

public class MyKeyboardView extends KeyboardView {
@Override
public void onDraw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setTextAlign(Paint.Align.CENTER);
    Typeface font = Typeface.createFromAsset(context.getAssets(),
        "fonts/Hippie.otf"); //Insert your font here.
    paint.setTypeface(font);

    List<Key> keys = getKeyboard().getKeys();
    for(Key key: keys) {
        if(key.label != null)
            canvas.drawText(key.label.toString(), key.x, key.y, paint);
        }
    }
}
import java.lang.reflect.Field; 
import android.content.Context;
import android.graphics.Typeface;

public final class FontsOverride {

public static void setDefaultFont(Context context,
        String staticTypefaceFieldName, String fontAssetName) {
    final Typeface regular = Typeface.createFromAsset(context.getAssets(),
            fontAssetName);
    replaceFont(staticTypefaceFieldName, regular);
}

protected static void replaceFont(String staticTypefaceFieldName,
        final Typeface newTypeface) {
    try {
           final Field staticField = Typeface.class
                .getDeclaredField(staticTypefaceFieldName);
           staticField.setAccessible(true);
           staticField.set(null, newTypeface);
        } catch (NoSuchFieldException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
  }
}