博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Remaining Backward Compatible 保持向后兼容
阅读量:4046 次
发布时间:2019-05-24

本文共 1977 字,大约阅读时间需要 6 分钟。

The and action bar are only available on Android 3.0 and later. To support older platforms, you can fall back to the search dialog. The search dialog is a system provided UI that overlays on top of your application when invoked. http://blog.csdn.net/sergeycao

Set Minimum and Target API levels

To setup the search dialog, first declare in your manifest that you want to support older devices, but want to target Android 3.0 or later versions. When you do this, your application automatically uses the action bar on Android 3.0 or later and uses the traditional menu system on older devices:

...

Provide the Search Dialog for Older Devices

To invoke the search dialog on older devices, call whenever a user selects the search menu item from the options menu. Because Android 3.0 and higher devices show the in the action bar (as demonstrated in the first lesson), only versions older than 3.0 call when the user selects the search menu item.

@Overridepublic boolean onOptionsItemSelected(MenuItem item) {    switch (item.getItemId()) {        case R.id.search:            onSearchRequested();            return true;        default:            return false;    }}

Check the Android Build Version at Runtime

At runtime, check the device version to make sure an unsupported use of does not occur on older devices. In our example code, this happens in the method:

@Overridepublic boolean onCreateOptionsMenu(Menu menu) {    MenuInflater inflater = getMenuInflater();    inflater.inflate(R.menu.options_menu, menu);    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {        SearchManager searchManager =                (SearchManager) getSystemService(Context.SEARCH_SERVICE);        SearchView searchView =                (SearchView) menu.findItem(R.id.search).getActionView();        searchView.setSearchableInfo(                searchManager.getSearchableInfo(getComponentName()));        searchView.setIconifiedByDefault(false);    }    return true;}
你可能感兴趣的文章
驱动TFT要SDRAM做为显示缓存
查看>>
使用file查看可执行文件的平台性,x86 or arm ?
查看>>
qt5 everywhere 编译summary
查看>>
qt5 everywhere编译完成后,找不到qmake
查看>>
qt 创建异形窗体
查看>>
可重入函数与不可重入函数
查看>>
简单Linux C线程池
查看>>
内存池
查看>>
输入设备节点自动生成
查看>>
GNU hello代码分析
查看>>
Qt继电器控制板代码
查看>>
wpa_supplicant控制脚本
查看>>
gstreamer相关工具集合
查看>>
RS232 四入四出模块控制代码
查看>>
gstreamer插件之 videotestsrc
查看>>
linux 驱动开发 头文件
查看>>
/etc/resolv.conf
查看>>
container_of()传入结构体中的成员,返回该结构体的首地址
查看>>
linux sfdisk partition
查看>>
ipconfig,ifconfig,iwconfig
查看>>