Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android Search Interface - how to remove app icon when onSearchRequested() called

expanding SearchView widget on ActionBar

On MainActivity.class, i call a search dialog by onSearchRequested(). That how it shows up as image above.

I want to removed that home/app icon but no luck. Please don't confuse that i want to removed home/app icon on action bar. No, this is a Search dialog which i declared on 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);
    }
}}

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

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

This is v21/styles.xml i used

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

Another question if you don't mind. As i declare darkorange color for the status bar, and it works well. But when onSearchRequested() is called, the status bar is changed to black (as image above). How can i fix that too?

like image 272
laph Avatar asked Jan 28 '15 18:01

laph


1 Answers

Try either according to your scenario

getSupportActionBar().setDisplayShowHomeEnabled(false);

or

getActionBar().setIcon(new 
ColorDrawable(getResources().getColor(android.R.color.transparent))); 
like image 159
Viswanath Lekshmanan Avatar answered Oct 14 '22 22:10

Viswanath Lekshmanan