AppCompatActivity中使用SearchView
2016-09-10 14:04
239 查看
一、菜单配置文件
二、获取SearchView
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:res-auto="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/menu_item_search" android:title="@string/search" android:icon="@android:drawable/ic_menu_search" res-auto:showAsAction="ifRoom" res-auto:actionViewClass="android.support.v7.widget.SearchView"/> </menu>
二、获取SearchView
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.fragment_photo_gallery,menu); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.HONEYCOMB){ MenuItem item=menu.findItem(R.id.menu_item_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); SearchManager manager= (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE); ComponentName name=getActivity().getComponentName(); SearchableInfo info=manager.getSearchableInfo(name); searchView.setSearchableInfo(info); } }
相关文章推荐
- 使用appcompat_v7,定义activity全屏或无标题栏
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- ActionBarActivity+AppCompatActivity操作栏功能的使用
- AppCompatActivity与toolbar结合的详细使用
- 使用appcompat_v7,实现Dialog类型无标题栏和ActionBar的Activity
- Activity使用主题不兼容报错-You need to use a Theme.AppCompat theme (or descendant) with this activity
- AppCompatActivity 下使用SearchView为null的问题
- 使用appcompat_v7,定义activity全屏或无标题栏
- 使用ActionBar,调整Theme时遇到You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- void android.app.Activity.overridePendingTransition(int enterAnim, int exitAnim) 的使用
- 使用Dev Tools查看App的包名和所有Activity
- boolean android.app.Activity.isFinishing()函数使用
- 如何使用android-support-v7-appcompat
- 使用javah生成.h文件, 出现无法访问android.app,Activity的错误的解决
- 命令行下使用javah命令生成.h文件,出现“错误: 无法访问android.app.Activity 找不到android.app.Activity的类文件”的解决方法
- 使用Android ADT最新开发工具后,新建项目出现appcompat v7 他是什么?
- 关于cmd使用javah生成.h时出现:无法访问android.app.Activity 找不到android.app.activity的类文件
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 使用NativeExtension向AIR app 添加Activity和BroadCastReceiver(2)