一:有EditTexit时自动获取焦点
一、得到焦点不弹出输入框, 隐藏软键盘; android
二、不让文本框得到焦点;code
方法一:server
在<activity>标签中加入: android:windowSoftInputMode = "stateHidden"xml
方法二:get
在OnCreate()中it
getWindow().setSoftInputMode( WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)io
方法三:class
咱们能够抢占文本框的焦点,如在其父窗体中加入:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".MainActivity" >
<EditText
android:id="@+id/etMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout> List
二:默认弹出的键盘模式就是数字键盘。方法
EditText et = (EditText) findViewById(R.id.editNum);
et.setInputType(InputType.TYPE_CLASS_NUMBER);
给你的EditText设置输入类型 TYPE_CLASS_NUMBER,这样你在点击EditText的时候,默认弹出的键盘模式就是数字键
盘。
三:获取软键盘高度:
mRootWindow = getWindow();mRootView = mRootWindow.getDecorView().findViewById(android.R.id.content);mRootView.getViewTreeObserver().addOnGlobalLayoutListener( new ViewTreeObserver.OnGlobalLayoutListener() { public void onGlobalLayout(){ Rect r = new Rect(); View view = mRootWindow.getDecorView(); view.getWindowVisibleDisplayFrame(r); // r.left, r.top, r.right, r.bottom } });