- 浏览: 420221 次
- 性别:
- 来自: 深圳/湛江
文章分类
最新评论
-
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 7866使用 Matrix 的随触摸旋转的ImageView 突 ... -
[android]动态改变按钮背景状态 StateListDrawable
2012-10-29 10:52 1426动态改变按钮背景状态 很少用到 上次和六哥聊到。 ... -
[android]ViewPage上无法通过onKeyDown()获得按钮事件
2012-08-20 04:53 1331系统无法监听到遥控器在VewPage上的按钮事件,如需 ... -
[android]待解决 lisTview 的onItemSelected 监听事件焦点的问题。
2012-08-18 21:18 2137今天遇到个问题 到目前为止 一直不理解为什么 大概描述下布局 ... -
[android]layout_weight 在layout_width 为fill_parent 与wrap_content 时的不同含义
2012-08-12 12:52 1238转自:http://hi.baidu.com/l ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 3986研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 3研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]仿制新浪微博消息页面 图标切换动画
2012-08-10 17:33 0研究了下以前不怎么用到的动画效果的实现 顺便做了一个新浪微 ... -
[android]Activity切换动画
2012-08-10 12:23 1445今天准备比赛的时候 遇到了这个问题。 查了些资料 ... -
android中ADT版本问题:无故报 java.lang.NoClassDefFoundError
2012-07-31 22:08 1746今天修改一个老项目的时候,发现在所有配置正确的情况下,代目无任 ... -
[android]仿360状态,类流量监控桌面浮动显示
2012-05-27 22:03 5978前两天看到部分音频播放器可以实现在桌面上显示歌词,360那个浮 ... -
[转]android开发问题记录 "founderapp"
2012-02-08 10:48 1028这段时间,由于某种原因,一直在做android手机开发, ... -
关于weight
2012-02-05 21:20 807layout_weight=1后,除了其它的控件之外剩 ... -
判断SD卡是否存在
2012-02-02 17:54 835android.os.Environment.getEx ... -
[转]Android文件管理器介绍
2012-02-02 16:50 3045转自:http://www.linuxidc.com/L ... -
[转]Android文件管理器介绍
2012-02-02 16:49 5转自:http://www.linuxidc.com/L ... -
[转]android 几何图形的绘制
2012-02-01 16:06 2144转自:http://byandby.iteye.c ... -
Android菜鸟日记32-游戏中的碰撞
2012-01-11 23:09 1720Android菜鸟日记 32-游戏中的碰撞 一、 ... -
Android菜鸟日记31-selector 中使用 shape
2012-01-11 23:05 1558Android菜鸟日记 31- ... -
Android菜鸟日记30-View与SurfaceView
2012-01-11 22:45 911Android菜鸟日记 30 View与Surfa ...
相关推荐
一般的我们去切换屏幕方向都是不希望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|
在AndroidMainfest.xml中选择哪个activity,设置windowSoftInputMode属性为adjustUnspecified|stateHidden 例如: <activity android:name=".Main" android:label="@string/app_name" android:...
1. 在AndroidManifest.xml中为Activity设置configChanges属性, application android:icon=@drawable/icon android:label=@string/app_name> <activity android:name=.MainActivity android:label=@string/app_...
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 例如: <...
这种情况适用于屏幕旋转和配置变化,只要作用是阻止Activity重建,因此对于【语言】【时区】的调整可能需要重新启动Activity才能更新。 注意: 语言的变化需要配置为 android:configChanges=locale|layoutDirection...