android EditText(文本输入框)去掉 系统软件盘的方法

默认状态下,当咱们点击文本输入框时,会弹出系统软键盘。 当在大屏幕的android设备上有输入需求时,系统软键盘的已输入文本会感受字体有些小,不容易看清。本人也未找到方大软键盘输入时文本的方法。只好经过禁用系统软键盘,开发本身的键盘的方法补救!

 

禁用系统软键盘方法1: android

在你的Activity的onCreate()方法中加入如下代码: ide

EditText edittext=(EditText )findViewById(R.id.xx); 布局

edittext.setInputType(InputType.TYPE_NUMBER_VARIATION_NORMAL); 字体

 

禁用系统软键盘方法2: this

在你的Activity的onCreate()方法中加入如下代码: 接口

EditText edittext=(EditText )findViewById(R.id.xx); 事件

edittext.setKeyListener(null); 开发

若是须要侦听遥控器数字按键,上面句需改为edittext.setKeyListener(this);而后在你的activity里实现KeyListener接口,接口方法贴出: get

@Override it

public void clearMetaKeyState(View view, Editable editable, int i) {

// TODO Auto-generated method stub

 

}

 

@Override

public int getInputType() {

// TODO Auto-generated method stub

return 0;

}

 

@Override

public boolean onKeyDown(View view, Editable editable, int i,

KeyEvent keyevent) {

if (keyevent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {

hideSoftKeyBoard(true);           ③

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_0) {

numBtnVal = "0";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_1) {

numBtnVal = "1";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_2) {

numBtnVal = "2";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_3) {

numBtnVal = "3";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_4) {

numBtnVal = "4";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_5) {

numBtnVal = "5";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_6) {

numBtnVal = "6";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_7) {

numBtnVal = "7";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_8) {

numBtnVal = "8";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_9) {

numBtnVal = "9";

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_CTRL_LEFT) {

if (curFocusPosi > 0) {

curFocusPosi--;

} else {

curFocusPosi = 0;

}

setEditTextVal();

return true;

} else if (keyevent.getKeyCode() == KeyEvent.KEYCODE_CTRL_RIGHT) {

if (curFocusPosi < tmpSNVal.length()) {

curFocusPosi++;

}

setEditTextVal();

return true;

} else {

return false;

}

 

}

 

@Override

public boolean onKeyOther(View view, Editable editable, KeyEvent keyevent) {

// TODO Auto-generated method stub

return true;

}

 

@Override

public boolean onKeyUp(View view, Editable editable, int i,

KeyEvent keyevent) {

// TODO Auto-generated method stub

return true;

}

 

其中红色标出的 ③处是弹出咱们本身的键盘。自定义键盘的全部button放在id为softInputArea的相对布局中,并实现按钮的点击事件numBtnClickHandler(View source),从而改变edittext的内容。

  private void hideSoftKeyBoard(boolean showOrHide) {

RelativeLayout keyBoardLayout = (RelativeLayout) findViewById(R.id.softInputArea);

if (keyBoardLayout != null) {

     if (showOrHide) {

            keyBoardLayout.setVisibility(View.GONE);

     } else {

            keyBoardLayout.setVisibility(View.VISIBLE);

}

                 }

}

 

部分自定义键盘布局:

<RelativeLayout

            android:id="@+id/softInputArea"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_gravity="right"

            android:background="@drawable/ic_keyboard_backgroud"

            android:visibility="visible" >

               //数字1

            <Button

                android:id="@+id/btn1"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:background="@drawable/number1_button_style"

                android:focusable="true"

                android:onClick="numBtnClickHandler" />

             //数字2

            <Button

                android:id="@+id/btn2"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_toRightOf="@id/btn1"

                android:background="@drawable/number2_button_style"

                android:focusable="true"

                android:onClick="numBtnClickHandler" />

     。。。。。。

       咱们必须在activity中实现点击事件的自定义方法 numBtnClickHandler(View source)方法,经过形参View source咱们能够得知是哪一个按钮被点击,而后对各个按钮进行处理,同时给edittext赋值!!

public void numBtnClickHandler(View source) {

 

if (source != null) {

if (source.getId() == R.id.btn0) {

numBtnVal = "0";

} else if (source.getId() == R.id.btn1) {

numBtnVal = "1";

} else if (source.getId() == R.id.btn2) {

numBtnVal = "2";

} else if (){.......}

相关文章
相关标签/搜索