App>Activity>SoftInputModes键盘显示方式
有四种显示方式,其中两种是一样的。
public class SoftInputModes extends Activity {
Spinner mResizeMode;
final CharSequence[] mResizeModeLabels = new CharSequence[] {
"Unspecified", "Resize", "Pan", "Nothing"
};
final int[] mResizeModeValues = new int[] {
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED,//整个布局上移,刚好到要输入的位置。
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE,//整个布局不动,但是要输入的位置布局上移。
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN,//整个布局上移,刚好到要输入的位置。
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING,//整个布局不动,遮挡输入位置。
};
/**
* Initialization of the Activity after it is first created. Here we use
* {@link android.app.Activity#setContentView setContentView()} to set up
* the Activity's content, and retrieve the EditText widget whose state we
* will persistent.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soft_input_modes);
mResizeMode = (Spinner)findViewById(R.id.resize_mode);
//一个简单的arrayadapter ,String类型的
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
android.R.layout.simple_spinner_item, mResizeModeLabels);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mResizeMode.setAdapter(adapter);
mResizeMode.setSelection(0);
mResizeMode.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent, View view, int position, long id) {
//设置window的显示输入键盘的方式
getWindow().setSoftInputMode(mResizeModeValues[position]);
}
public void onNothingSelected(AdapterView<?> parent) {
getWindow().setSoftInputMode(mResizeModeValues[0]);
}
});
}
}