android 搜索界面 - 如何在调用 onSearchRequested() 时删除应用程序图标

标签 android searchview android-search

expanding SearchView widget on ActionBar

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);
    }
}}

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">

关于 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>

这是我用过的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>

如果你不介意的话,再问一个问题。当我为状态栏声明 darkorange 颜色时,效果很好。但是当 onSearchRequested() 被调用时,状态栏变为黑色(如上图)。我该如何解决?

最佳答案

根据您的情况尝试其中一种

getSupportActionBar().setDisplayShowHomeEnabled(false);

getActionBar().setIcon(new 
ColorDrawable(getResources().getColor(android.R.color.transparent))); 

关于android 搜索界面 - 如何在调用 onSearchRequested() 时删除应用程序图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28199451/

相关文章:

android - 收集首选项失败,在 C :\Program Files (x86)\Android\android-sdk\platforms\android-19\android. jar 中找不到类 java/lang/Au​​toCloseable

java - 如何在 CustomAdapter 类中调用新 Intent ?

java - 如何将一种用户类型的列表复制到其他类型的列表?

android - 操作栏中的 Xamarin Android 搜索 View 为空

java - setKeyListener 将覆盖 setInputType 并更改键盘

android - 操作栏 - ifRoom 选项留下太多空间

Android 拇指不在搜索栏中心?

android - 从 MenuItem 获取 SearchView 返回 View 而不是 SearchView

安卓加载器 : When and why would the data content in the data-source change?

android - 如何在工具栏 Android 的 SearchView 小部件中删除白色下划线