Posted on 2010-06-21 21:18
David.Ko 阅读(1636)
评论(0) 编辑 收藏 所属分类:
Android
G1带有实体键盘,可以侧推。虽然如今的G2 G3去掉了实体键盘,但同志们开发的应用还是得兼容一下G1吧。先从几个问题入手:
1、不管键盘是否滑出,都要设置屏幕为竖屏或者横屏。这个该怎么处理?
2、当用户在竖屏状态下编辑了一个文本框,又突然想推出实体键盘进行编辑,而此时Activity重绘,文本框内未保存的信息又该怎么办?
3、监听键盘滑动事件。让纵横屏状态下载入不同的layout。
当然你也许可以再java代码中去设置很多事件捕获,但有一个更好的方法,那就是修改Androidmanifest.xml.
默认的情况下推出或缩进键盘会重新启动activity
要不关闭activity 则可以在manifest.xml中增加 android:configChanges=”keyboardHidden|orientation”
然后重载public void onConfigurationChanged(Configuration newConfig) 函数
键盘被抽出后会首先调用onConfigurationChanged
如果你希望滑动键盘不改变屏幕分辨率 则可以增加属性:android:screenOrientation=”portrait“>
portrait :竖
landscape: 横
sensor:根据手机的角度自动调整
详细说明:
<activity …
android:configChanges=[one or more of: "mcc" "mnc" "locale"
"touchscreen" "keyboard" "keyboardHidden"
"navigation" "orientation" "fontScale"]
…
</activity>
android:configChanges
Lists configuration changes that the activity will handle itself. When changes that are not listed occur, the activity is shut down and restarted. When a listed change occurs, the activity remains running and its onConfigurationChanged() method is called.
Any or all of the following strings can be used to set this attribute. Values are separated by ‘|’ — for example, “locale|navigation|orientation”.
Value Description
“mcc” The IMSI mobile country code (MCC) has changed — that is, a SIM has been detected and updated the MCC.
“mnc” The IMSI mobile network code (MNC) has changed — that is, a SIM has been detected and updated the MNC.
“locale” The locale has changed — for example, the user has selected a new language that text should be displayed in.
“touchscreen” The touchscreen has changed. (This should never normally happen.)
“keyboard” The keyboard type has changed — for example, the user has plugged in an external keyboard.
“keyboardHidden” The keyboard accessibility has changed — for example, the user has slid the keyboard out to expose it.
“navigation” The navigation type has changed. (This should never normally happen.)
“orientation” The screen orientation has changed — that is, the user has rotated the device.
“fontScale” The font scaling factor has changed — that is, the user has selected a new global font size.
All of these configuration changes can impact the resource values seen by the application. Therefore, when onConfigurationChanged() is called, it will generally be necessary to again retrieve all resources (including view layouts, drawables, and so on) to correctly handle the change.