android笔记

1、android:password is deprecated: Use inputType instead

android:password="true"
更改为:
android:inputType="textPassword"


2、missing contentdescription attribute on image
ADT 16.0的新特性,在一些没有文本显示的控件里,如imageView和imageButton等,ADT会提示你定义一个android:contentDescription属性

3、android弹窗
http://blog.csdn.net/centralperk/article/details/7493731

4、RadioGroup中的RadioButton分别都要设置自己的id,这样就可以互斥选择了

5、选中RadioGroup选中的值
RadioButton radiobtn = (RadioButton) settingLang.findViewById(settingLang.getCheckedRadioButtonId());
int radioInt = Integer.parseInt(radiobtn.getTag().toString());

6、设置语种切换
1、各国语言缩写-各国语言简称,世界各国域名缩写
http://blog.csdn.net/snlei/article/details/3788925
2、在工程res文件下添加对应语种的values文件 eg:values-en
3、
//应用内配置语言
Resources resources =getResources();//获得res资源对象 
Configuration config = resources.getConfiguration();//获得设置对象 
DisplayMetrics dm = resources.getDisplayMetrics();//获得屏幕参数:主要是分辨率,像素等。
config.locale = Locale.SIMPLIFIED_CHINESE; //简体中文
resources.updateConfiguration(config, dm);
4、设置跳转后才会切换语种
// Intent intent = getIntent();
//         finish();
//         startActivity(intent);

5、如果没有的语种可以直接new
config.locale =new Locale("ar");
7、在代码中设置RadioGroup的默认选中
RadioGroup.check(R.id.setting_lang_en);

8、保存值到对应资源文件中
8.1
SharedPreferences的四种操作模式:
Context.MODE_PRIVATE
Context.MODE_APPEND
Context.MODE_WORLD_READABLE
Context.MODE_WORLD_WRITEABLE

Context.MODE_PRIVATE:为默认操作模式,代表该文件是私有数据,只能被应用本身访问,在该模式下,写入的内容会覆盖原文件的内容
Context.MODE_APPEND:模式会检查文件是否存在,存在就往文件追加内容,否则就创建新文件.
Context.MODE_WORLD_READABLE和Context.MODE_WORLD_WRITEABLE用来控制其他应用是否有权限读写该文件.
MODE_WORLD_READABLE:表示当前文件可以被其他应用读取.
MODE_WORLD_WRITEABLE:表示当前文件可以被其他应用写入.

8.2
将数据保存至SharedPreferences:
SharedPreferences preferences=getSharedPreferences("user",Context.MODE_PRIVATE);
Editor editor=preferences.edit();
String name="xixi";
String age="22";
editor.putString("name", name);
editor.putString("age", age);
editor.commit();

从SharedPreferences获取数据:
SharedPreferences preferences=getSharedPreferences("user", Context.MODE_PRIVATE);
String name=preferences.getString("name", "defaultname");
String age=preferences.getString("age", "0");

猜你喜欢

转载自oliven102201.iteye.com/blog/2086603