lap*_*aph 6 android searchview android-search

在 上MainActivity.class,我调用了一个搜索对话框onSearchRequested()。它如何显示为上图。
我想删除那个主页/应用程序图标,但没有运气。请不要混淆我想删除操作栏上的主页/应用程序图标。不,这是我声明的搜索对话框SearchActivity.class
public class SearchableActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);
// Get the intent, verify the action and get the query
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
doMySearch(query);
}
}}
Run Code Online (Sandbox Code Playgroud)
并在 xml/searchable.xml
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer">
Run Code Online (Sandbox Code Playgroud)
在 AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.default_searchable"
android:value=".SearchableActivity"/>
</activity>
<activity
android:name=".SearchableActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
</activity>
</application>
Run Code Online (Sandbox Code Playgroud)
这是v21/styles.xml我用过的
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/orange</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/darkorange</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/brown</item>
<!-- title bar text color -->
<item name="android:textColorPrimary">@color/white</item>
<!-- no action bar -->
<item name="android:windowNoTitle">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如果你不介意的话,另一个问题。当我darkorange为状态栏声明颜色时,它运行良好。但是当onSearchRequested()被调用时,状态栏变为黑色(如上图)。我该如何解决?
根据您的场景尝试一下
getSupportActionBar().setDisplayShowHomeEnabled(false);
Run Code Online (Sandbox Code Playgroud)
或者
getActionBar().setIcon(new
ColorDrawable(getResources().getColor(android.R.color.transparent)));
Run Code Online (Sandbox Code Playgroud)