笔记:Android判断版本并根据版本使用不同的代码以及旧版本XML问题
来源:互联网 发布:java 日期格式化 毫秒 编辑:程序博客网 时间:2024/05/29 03:26
Android provides a unique code for each platform version in the Build
constants class. Use these codes within your app to build conditions that ensure the code that depends on higher API levels is executed only when those APIs are available on the system.
private void setUpActionBar() { // Make sure we're running on Honeycomb or higher to use ActionBar APIs if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); }}
在我们自己开发应用过程中,常常使用如下的代码形式判断运行新API还是旧的API:if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
// 包含新API的代码块
}
else
{
// 包含旧的API的代码块
}
Note: When parsing XML resources, Android ignores XML attributes that aren’t supported by the current device. So you can safely use XML attributes that are only supported by newer versions without worrying about older versions breaking when they encounter that code. For example, if you set thetargetSdkVersion="11"
, your app includes the ActionBar
by default on Android 3.0 and higher. To then add menu items to the action bar, you need to set android:showAsAction="ifRoom"
in your menu resource XML. It's safe to do this in a cross-version XML file, because the older versions of Android simply ignore theshowAsAction
attribute (that is, you do not need a separate version in res/menu-v11/
).
0 0
- 笔记:Android判断版本并根据版本使用不同的代码以及旧版本XML问题
- hibernate4.2版本sessionFactory方法和旧版本的不同
- SVN版本比较时旧版本的中文乱码问题
- Android不同版本的判断
- android 版本更新 同时清除旧版本数据
- iOS_根据系统版本编译不同的代码
- Java笔记(三)--不同版本jdk以及tomcat共存的问题
- 根据不同的manifest.xml使用repo同步代码
- 不同版本jdk以及tomcat共存的问题
- 判断android的版本
- Android - 资源xml文件适配不同的版本
- IAR for 8051 使用10.10版本时旧版本工程编译错误解决方法
- iOS 不同版本 判断
- iOS 根据不同的系统版本加载不同图片方法
- 不同版本的Android操作系统
- Android不同版本的版本号
- MSXML的不同版本使用
- 如何下载旧版本的Eclipse,或者查看之前发布的版本。
- 一个下载各种统计年鉴的好去处
- Space Shooter之控制陨石随机旋转
- windows下删除.svn命令
- win下远程连接linux下mysql
- Gson的简单使用(二)
- 笔记:Android判断版本并根据版本使用不同的代码以及旧版本XML问题
- 四个程序题!
- C++:浅谈工厂模式与抽象工厂模式
- 如何开好传奇,SF怎么开赚钱,开传奇SF要多少钱?qq9 3 4 1 1 3 4 1 7
- CentOS 的使用 —— 各种格式文件的解压
- 73条linux shell命令汇总
- 分享手机兼容性测试一个很好的网站,腾讯优测
- Markdown-写作必备
- delphi 单引号用quotedstr()就是爽