通过设置这个属性可以使Activity捕捉设备状态变化,以下是可以被识别的内容:
CONFIG_FONT_SCALE
CONFIG_MCC
CONFIG_MNC
CONFIG_LOCALE
CONFIG_TOUCHSCREEN
CONFIG_KEYBOARD
CONFIG_NAVIGATION
CONFIG_ORIENTATION
设置方法:将下列字段用“|”符号分隔开,例如:“locale|navigation|orientation
”
Value Description
“mcc“ The IMSI mobile country code (MCC) has changed — that is, a SIM hasbeen detected and updated the MCC.移动国家号码,由三位数字组成,每个国家都有自己独立的MCC,可以识别手机用户所属国家。
“mnc“ The IMSI mobile network code (MNC) has changed — that is, a SIM hasbeen 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.全局字体大小缩放发生改变
通过一个例子介绍这个属性的用法: 首先需要修改项目的manifest:
?View Code XML
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidres.ConfigChangedTesting"
android:versionCode="1"
android:versionName="1.0.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ConfigChangedTesting"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
在Activity中添加了 android:configChanges属性,目的是当所指定属性(Configuration Changes)发生改变时,通知程序调用 onConfigurationChanged()函数。 创建一个Layout UI:
?View Code XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/pick"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Pick"
/>
<Button
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="View"
/>
</LinearLayout>
这个简单的UI包含两个按钮,其中一个是通过Contact列表选择一个联系人,另外一个是查看当前选择联系人的详细内容
项目的Java源代码:
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.view.View;
import android.widget.Button;
public class ConfigChangedTesting extends Activity {
/** Called when the activity is first created. */
static final int PICK_REQUEST = 1337;
Button viewButton=null;
Uri contact = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setupViews();
}
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setupViews();
}
/* (non-Javadoc)
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
//super.onActivityResult(requestCode, resultCode, data);
if(requestCode == PICK_REQUEST){
if(resultCode==RESULT_OK){
contact = data.getData();
viewButton.setEnabled(true);
}
}
}
private void setupViews(){
setContentView(R.layout.main);
Button pickBtn = (Button)findViewById(R.id.pick);
pickBtn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i=new Intent(Intent.ACTION_PICK,People.CONTENT_URI);
startActivityForResult(i,PICK_REQUEST);
}
});
viewButton =(Button)findViewById(R.id.view);
viewButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(Intent.ACTION_VIEW, contact));
}
});
viewButton.setEnabled(contact!=null);
}
}
分享到:
相关推荐
一般的我们去切换屏幕方向都是不希望Activity被重新创建,这时就需要对一些属性进行设置,或者使用代码设置。文章通过以上方面解析Activity在横竖屏切换时,生命周期方法执行过程。 1.Activity生命周期 2....
ActivityAttacher就是附着在上面4个模板Activity里的Activity代理ActivityAttacher中持有一个Activity实例对象,是在onCreate时赋值的ActivityAttacher可以处理Activity中的所有配置和生命周期ActivityAttacher提供...
方法一: 通过Theme.Translucent ...只需要在Manifest中需要透明的Activity内设置theme为以上任意一个就可以了 <activity android:name=com.vixtel.simulate.MainApp android:configChanges=keyboardHidden|
1. 在AndroidManifest.xml中为Activity设置configChanges属性, application android:icon=@drawable/icon android:label=@string/app_name> <activity android:name=.MainActivity android:label=@string/app_...
在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 例如: <activity android:name=".Main" android:label="@string/app_name" android:...
android:configChanges="orientation|keyboardHidden"的使用-附件资源
首先在Mainifest.xml的Activity元素中加入android:configChanges=”orientation|keyboardHidden”属性 <activityandroid name=.FileBrowserandroid:label app_nameandroid:configChanges=orientation|...
最近在Android项目中使用拍照功能 , 其它型号的手机运行成功了 唯独在三星的相机上遇到了bug . BUG具体体现为 : (1) 摄像头拍照后图片数据不一定能返回 ; onActivityResult的data为空 (2) 三星的camera强制切换到...
android:name="android.permission.READ_EXTERNAL_STORAGE"/>注意,如果横竖屏切换不想重新走一遍生命周期,还需要在表单中设置Activity的configChanges属性:<activity android:name=".PlayActivity" ...
为了避免activity 重新加载过程中有闪屏的现象,则需要再清单文件中配置该activity 的属性 android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation|screenSize",详细信息请参阅...
这个是Android 4高级编程第三版的完整pdf文档,受最大上传大小的限制,切分成了十份,每份就最好的数字不一样,比如说第二份就是Android 4 高级编程第三版_2,代码可以在清华出版社的网站上下载
部分网友会发现Activity在切换到后台或布局从横屏LANDSCAPE切换到PORTRAIT,会重新切换Activity会触发一次onCreate方法,我们可以在androidmanifest.xml中的activit元素加入这个属性Android:configChanges=”...
FragmentDemo
解决方法:在manifest文件里面给activity加上下面一行属性 android:configChanges=screenSize|smallestScreenSize|screenLayout|orientation 2.当启用多窗口模式时,可能有改变原UI的需求,这时可以在代码里面修改...
在 AnroidMainifest.xml 的 activity 元素中加入: 代码如下:android:configChanges=”orientation|keyboardHidden”或 代码如下:android:configChanges=”orientation|keyboard|keyboardHidden” 表示在改变屏幕...
guolin的fragmentdemo, 修改了切屏时重叠问题, AndroidManifest <activity加入 android:configChanges="keyboardHidden|orientation|screenSize" 即可
在您的AndroidManifest文件查找中包含相应的活动标签,并将android:configChanges="orientation|screenSize"到其中。 现在您的活动标签将类似于<activity name= ".YourActivity" android:configChanges=...
1. 在AndroidManifest.xml中将需要默认隐藏键盘的Activity中添加属性即可(常用此方法) android:windowSoftInputMode=adjustUnspecified|stateHidden android:configChanges=orientation|keyboardHidden 例如: <...
解决方案1:在Androidmanifest.xml的activity标签中加入android:configChanges=”orientation|keyboardHidden” <activity android:configChanges=orientation|keyboardHidden android:label=sqltest android...