- 浏览: 430973 次
- 性别:
- 来自: 深圳/湛江
-
文章分类
最新评论
-
wangyudong:
很多API doc生成工具生成doc需要重度依赖代码里加注解的 ...
[ios]利用xcode自动生成项目文档 -
tiger1819:
有源码么,想学习
[android]仿360状态,类流量监控桌面浮动显示 -
119568242:
借我一双翅膀 写道大哥,求指教啊?
IOS 开发,调用打电话,发短信,打开网址 -
借我一双翅膀:
大哥,求指教啊
IOS 开发,调用打电话,发短信,打开网址 -
li247276297:
楼主 是不是要加个权限?
[android]仿360状态,类流量监控桌面浮动显示
[转载]Activity中ConfigChanges属性的用法
CONFIG_FONT_SCALE
CONFIG_MCC
CONFIG_MNC
CONFIG_LOCALE
CONFIG_TOUCHSCREEN
CONFIG_KEYBOARD
CONFIG_NAVIGATION
CONFIG_ORIENTATION
设置方法:将下列字段用“|”符号分隔开,例如:“locale|navigation|orientation
”
通过一个例子介绍这个属性的用法: 首先需要修改项目的manifest:
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.全局字体大小缩放发生改变
?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源代码:
01.import android.app.Activity;
02.import android.content.Intent;
03.import android.content.res.Configuration;
04.import android.net.Uri;
05.import android.os.Bundle;
06.import android.provider.Contacts.People;
07.import android.view.View;
08.import android.widget.Button;
09.
10.public class ConfigChangedTesting extends Activity {
11. /** Called when the activity is first created. */
12. static final int PICK_REQUEST = 1337;
13. Button viewButton=null;
14. Uri contact = null;
15. @Override
16. public void onCreate(Bundle savedInstanceState) {
17. super.onCreate(savedInstanceState);
18. //setContentView(R.layout.main);
19.
20. setupViews();
21. }
22.
23. public void onConfigurationChanged(Configuration newConfig) {
24. super.onConfigurationChanged(newConfig);
25.
26. setupViews();
27. }
28.
29. /* (non-Javadoc)
30. * @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
31. */
32. @Override
33. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
34. // TODO Auto-generated method stub
35. //super.onActivityResult(requestCode, resultCode, data);
36.
37. if(requestCode == PICK_REQUEST){
38.
39. if(resultCode==RESULT_OK){
40.
41. contact = data.getData();
42. viewButton.setEnabled(true);
43. }
44.
45. }
46.
47. }
48.
49. private void setupViews(){
50.
51. setContentView(R.layout.main);
52.
53. Button pickBtn = (Button)findViewById(R.id.pick);
54.
55. pickBtn.setOnClickListener(new View.OnClickListener(){
56.
57. public void onClick(View v) {
58. // TODO Auto-generated method stub
59.
60. Intent i=new Intent(Intent.ACTION_PICK,People.CONTENT_URI);
61. startActivityForResult(i,PICK_REQUEST);
62. }
63. });
64.
65. viewButton =(Button)findViewById(R.id.view);
66.
67. viewButton.setOnClickListener(new View.OnClickListener() {
68. public void onClick(View view) {
69. startActivity(new Intent(Intent.ACTION_VIEW, contact));
70. }
71. });
72.
73. viewButton.setEnabled(contact!=null);
74. }
75.}
发表评论
-
[android]使用 Matrix 的随触摸旋转的ImageView
2013-02-22 01:58 7956使用 Matrix 的随触摸旋转的ImageView 突 ... -
[android]动态改变按钮背景状态 StateListDrawable
2012-10-29 10:52 1492动态改变按钮背景状态 很少用到 上次和六哥聊到。 ... -
[android]ViewPage上无法通过onKeyDown()获得按钮事件
2012-08-20 04:53 1398系统无法监听到遥控器在VewPage上的按钮事件,如需 ... -
[android]待解决 lisTview 的onItemSelected 监听事件焦点的问题。
2012-08-18 21:18 2198今天遇到个问题 到目前为止 一直不理解为什么 大概描述下布局 ... -
[android]layout_weight 在layout_width 为fill_parent 与wrap_content 时的不同含义
2012-08-12 12:52 1280转自:http://hi.baidu.com/l ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 4063研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 3研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 0研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]Activity切换动画
2012-08-10 12:23 1494今天准备比赛的时候 遇到了这个问题。 查了些资料 ... -
android中ADT版本问题:无故报 java.lang.NoClassDefFoundError
2012-07-31 22:08 1819今天修改一个老项目的时候,发现在所有配置正确的情况下,代目无任 ... -
[android]仿360状态,类流量监控桌面浮动显示
2012-05-27 22:03 6065前两天看到部分音频播放器可以实现在桌面上显示歌词,360那个浮 ... -
[转]android开发问题记录 "founderapp"
2012-02-08 10:48 1088这段时间,由于某种原因,一直在做android手机开发, ... -
关于weight
2012-02-05 21:20 859layout_weight=1后,除了其它的控件之外剩 ... -
判断SD卡是否存在
2012-02-02 17:54 902android.os.Environment.getEx ... -
[转]Android文件管理器介绍
2012-02-02 16:50 3097转自:http://www.linuxidc.com/L ... -
[转]Android文件管理器介绍
2012-02-02 16:49 5转自:http://www.linuxidc.com/L ... -
[转]android 几何图形的绘制
2012-02-01 16:06 2212转自:http://byandby.iteye.c ... -
Android菜鸟日记32-游戏中的碰撞
2012-01-11 23:09 1769Android菜鸟日记 32-游戏中的碰撞 一、 ... -
Android菜鸟日记31-selector 中使用 shape
2012-01-11 23:05 1644Android菜鸟日记 31- ... -
Android菜鸟日记30-View与SurfaceView
2012-01-11 22:45 973Android菜鸟日记 30 View与Surfa ...
相关推荐
当设置为`true`时,此`Activity`将不会出现在“最近使用的应用”列表中。这对于敏感操作或隐私相关的`Activity`很有用,可以防止用户意外访问。 #### android:exported 决定`Activity`是否可以被其他应用组件调用。...
让 Android 横竖屏切换时不销毁当前的 Activity 需要使用 `android:configChanges` 属性和 `onConfigurationChanged` 方法。同时,我们也需要正确处理屏幕方向的改变,以确保应用程序的正确运行。
如果设置为"true",activity不会出现在最近使用的应用列表中,用户无法通过此列表快速回到该activity。 7. android:exported=["true" | "false"] 表示activity是否允许其他应用的组件(如意图)来调用。"true...
为了避免不必要的重建,可以通过在AndroidManifest.xml中指定Activity的android:configChanges属性,或重写onConfigurationChanged()方法来手动处理配置变化。 总结起来,Android的Activity是构建用户界面和实现...
默认情况下,Activity会全屏显示,但我们可以通过修改Activity的属性和使用自定义布局来改变这一行为。 1. 修改Activity的属性: 在AndroidManifest.xml中,可以为特定Activity添加`android:resizeableActivity=...
7. **处理配置变更**:如果`LauncherActivity`的布局可能因屏幕方向改变或其他配置变更而变化,需要适当地处理这些情况,例如使用`android:configChanges`属性或重写`onConfigurationChanged()`方法。 8. **测试与...
Fragment可以嵌入到Activity中,也可以独立存在。当Activity经历生命周期变化时,与其关联的Fragment也会相应地经历生命周期状态。 在Activity的屏幕旋转等配置更改时,Android默认会重新创建Activity及其包含的...
为了优化用户体验,避免每次屏幕方向改变时都重新创建`Activity`,可以在`AndroidManifest.xml`文件中为特定的`Activity`添加`android:configChanges`属性。例如: 1. **android:configChanges="orientation"**:...
开发者可以通过重写onSaveInstanceState()保存状态,onRestoreInstanceState()恢复状态,或者使用configChanges属性避免重启。 8. **TaskAffinity**:每个Activity都关联了一个任务亲和力,决定它应该属于哪个任务...
开发者可以使用`android:configChanges`属性来手动处理配置变更,避免不必要的重建。 六、Activity的保存与恢复状态 当Activity被系统销毁(如屏幕旋转)时,可以使用`onSaveInstanceState(Bundle)`保存当前状态,...
4. **android:configChanges**:指定哪些配置变化会导致Activity的`onConfigurationChanged()`方法被调用,如屏幕方向、导航方式或语言更改等。如果不想因为配置改变而重新创建Activity,可以手动处理这些变化。 5....
使用`android:configChanges`属性可以在XML清单文件中指定哪些配置更改应由Activity自己处理,而不是默认销毁并重建Activity。`onConfigurationChanged(Configuration newConfig)`方法可用于处理这些特定配置变化。 ...
通过修改`AndroidManifest.xml`中的`<activity>`标签,可以设置`android:theme`属性,使用预定义的主题或者自定义主题样式。 6. **多窗口支持**:从Android 7.0开始,`Activity`支持在分屏模式下运行。开发者需要...
通过在AndroidManifest.xml中对应的Activity标签中添加`android:configChanges="orientation|screenSize"`属性,指示系统不要销毁Activity,而是调用`onConfigurationChanged(Configuration newConfig)`方法来处理...
1. 使用`android:configChanges="orientation|screenSize"`属性,在AndroidManifest.xml中指定Activity对横竖屏变化的处理方式,让系统不再默认销毁Activity。 2. 在Activity中重写`onConfigurationChanged...
此外,如果你使用的是静态Fragment(即在布局文件中定义的Fragment),可能需要在Activity的`onCreate(Bundle savedInstanceState)`方法中移除并重新添加Fragment,以确保配置改变后能正确更新。 总之,处理...
默认情况下,配置变更会导致Activity重建,但可以通过在AndroidManifest.xml中设置`android:configChanges`属性或重写`onConfigurationChanged(Configuration newConfig)`来控制如何处理配置变更。 理解并熟练掌握...
开发者可以通过重写onSaveInstanceState()保存状态,并在onRestoreInstanceState()中恢复,或者使用configChanges属性避免不必要的重建。 7. **Fragment与Activity**:Fragment是Android 3.0引入的组件,可以嵌入到...
在名为"TestAndroid"的项目中,我们可以创建一个简单的Activity,覆盖上述提到的生命周期方法,并在每个方法内打印日志。通过改变设备状态,比如旋转屏幕,可以看到onSaveInstanceState和onConfigurationChanged...
12. 可以在Activity中覆写onSaveInstanceState(Bundle outState)和onRestoreInstanceState(Bundle savedInstanceState)方法,以保存和恢复Activity的状态,防止因系统原因导致的Activity销毁。 通过学习这个压缩包...