检查Android设备具有搜索硬件按钮 [英] Check if Android device has search hardware button
问题描述
我需要帮助搞清楚如何检查设备是否配备有搜索硬件按钮与否。这可能吗?
I need help figuring out how to check if a device is equipped with the search hardware button or not. Is this possible?
编辑:我说的是找出如果设备有搜索硬件按钮与否。简单的问题。每一个Android设备有一组硬件按钮;菜单,主页键,返回键以及搜索键。但有些设备仅配备了其中的一部分,不是全部。
I'm talking about finding out if the device has the search hardware button or not. Simple question. Each android device has a set of hardware buttons; menu, home button, back button, and search button. But some devices is only equipped with some of them, not all.
编辑2:为什么我问的是,因为我想有一个软件按钮会显示在用户界面,如果该设备的不是的配备了一个硬件按钮的原因。我现在用的是搜索接口在我的活动。我不继的EditText /文本字段的方法。
EDIT 2: The reason why I ask is because I want to have a software button showing in my UI if the device is not equipped with a hardware button. I am using the searchable interface in my activity. I am not following the EditText / TextField approach.
推荐答案
我不认为你需要检测,如果它确实有一个搜索硬件按钮。该框架将帮助你在这里(不过,我敢肯定,一旦冰淇淋三明治发布这一过程将被简化)
I don't think you need to detect if it actually has a search hardware button. The framework will help you out here (though, I'm sure this process will be simplified once Ice Cream Sandwich is released)
目前,这不会有硬件搜索的唯一设备是蜂窝片。因此,通过使用安卓targetSdkVersion =11
(或更高版本),加入实现OnQueryTextListener
您片段
或活动
,再加入类似:
Currently, the only devices that won't have hardware search are Honeycomb tablets. So, by using android:targetSdkVersion="11"
(or higher), adding implements OnQueryTextListener
to your Fragment
or Activity
, and then adding something like:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.notebooks_menu, menu);
final SearchView sv = new SearchView(getActivity());
sv.setOnQueryTextListener(this);
menu.findItem(R.id.search_notebooks).setActionView(sv);
}
您将主要解决的问题。现在,得到它的工作在pre-蜂窝设备,您可能需要使用兼容库,或使用反射或在code一些其他的后卫。
You will essentially solve the problem. Now, to get it working on pre-Honeycomb devices, you may need to use the compatibility library, or use reflection or some other guards in your code.
修改
三星Galaxy S II并没有一个专门的硬件搜索按钮,但是如果你的按住MENU按钮几秒钟,就开始作为一个硬件搜索按钮。的
The Samsung Galaxy S II does not have a dedicated hardware search button, but if you hold the menu button down for a couple of seconds, it will begin acting as a hardware search button.
这篇关于检查Android设备具有搜索硬件按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!