Searchview没有做任何事情,看起来它没有加载可搜索的信息。 它在免费构建中完美运行,但在专业版中不起作用。我已经尝试禁用proguard,尝试调试和发布版本。
主:
public boolean onCreateOptionsMenu(final Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.action_search_view).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
return true;
}
摇篮:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/repo' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/repo' }
}
android {
signingConfigs {
rollout {
}
}
compileSdkVersion 21
buildToolsVersion "21.0.1"
defaultConfig {
applicationId "me.example.dictionary"
minSdkVersion 15
targetSdkVersion 21
versionCode 3
versionName "1.01"
signingConfig signingConfigs.rollout
}
buildTypes {
release {
debuggable false
jniDebugBuild false
renderscriptDebugBuild false
zipAlign true
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.rollout
}
debug {
signingConfig signingConfigs.rollout
}
}
dexOptions {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
productFlavors {
free {
}
pro {
applicationId "me.example.dictionary.pro"
}
}
}
Searchable.xml
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_hint"
android:label="@string/app_name"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" />
答案 0 :(得分:7)
我遇到了同样的问题。搜索在主要风格中运行良好,但由于具有不同的应用ID,特定于客户端的风格存在问题(例如:com.company.app
vs com.company.app.clientflavor
)。
要修复,请更改
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
到
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, YourSearchableActivity.class)));
帽子提示this answer。