更改软键盘高度

时间:2019-12-06 05:29:08

标签: android android-softkeyboard

我需要减小横向模式下android软键盘的大小。

public class MainActivity extends AppCompatActivity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       /* MyKeyboard myKeyboard = new MyKeyboard(this,);   
        adjustKeyboardKeyHeight(myKeyboard,100);*/


    }

    private void adjustKeyboardKeyHeight (MyKeyboard keyboard, int newKeyHeight) {
        int oldKeyHeight = keyboard.getKeyHeight();
        int verticalGap = keyboard.getVerticalGap();
        int rows = 0;
        for (Keyboard.Key key : keyboard.getKeys()) {
            key.height = newKeyHeight;
            int row = (key.y + verticalGap) / (oldKeyHeight + verticalGap);
            key.y = row * newKeyHeight + (row - 1) * verticalGap;
            rows = Math.max(rows, row + 1);
        }
        keyboard.setHeight(rows * newKeyHeight + (rows - 1) * verticalGap);
    }

    private static class MyKeyboard extends Keyboard {
        private int height;
        MyKeyboard (Context context, int xmlLayoutResId) {
            super(context, xmlLayoutResId);
            height = super.getHeight();
        }
        @Override public int getKeyHeight() {
            return super.getKeyHeight();
        }
        @Override public int getVerticalGap() {
            return super.getVerticalGap();
        }
        public void setHeight (int newHeight) {
            height = newHeight;
        }
        @Override public int getHeight() {
            return height;
        }
    }
}

我对xmlLayoutResId传递什么有疑问
MyKeyboard myKeyboard = new MyKeyboard(this,); //在这一行中,我需要
知道该xmlLayoutResId要传递什么

0 个答案:

没有答案