Search code examples
androidandroid-layoutandroid-studioautocompletesearchview

SearchView AutoComplete is appearing with Black border and covering the searchtext?


Image how the searchView autocomplete is appearing

The searchView AutoComplete is appearing with black border as shown in image and I haven't made any custom layout still it is showing that black border and hiding the text.Below the code is also attached that I have used.`

 getMenuInflater().inflate(R.menu.main, menu);
            this.menu = menu;
            menuItem =  menu.findItem(R.id.action_search);
            searchView = (SearchView) MenuItemCompat.getActionView(menuItem);


            menuItem.setVisible(false);

            final SearchView.SearchAutoComplete searchAutoComplete =
                    searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);

            searchAutoComplete.setDropDownBackgroundResource(android.R.color.white);
            searchAutoComplete.setDropDownAnchor(R.id.action_search);
            ArrayAdapter<String> searchadapter = new ArrayAdapter<String>(this,
                   android.R.layout.simple_dropdown_item_1line,
                    all_products);
            searchAutoComplete.setAdapter(searchadapter);
    `

Menu Code It is the Item that is used for opening search option.

 <item android:id="@+id/action_search"
    android:title="@string/action_search"
    android:icon="@drawable/ic_search_white_24dp"
    app:showAsAction="collapseActionView|ifRoom"
    app:actionViewClass="android.support.v7.widget.SearchView"/>

AppBar layout Code It is the code made for Creating the App Action Bar But how this is affecting the search autocomplete to appear black border around it and hiding the search text.

  <android.support.design.widget.AppBarLayout
    android:id="@+id/main_app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clipChildren="false"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/main_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:theme="@style/CustomActionBar">

        <TextView
            android:layout_width="wrap_content"
            android:textColor="#FFF"
            android:textSize="18sp"
            android:textStyle="bold"
            android:layout_height="wrap_content"
            android:text="Avrutti Electronics"/>


            <ProgressBar
                android:id="@+id/progressBar4"
                style="?android:attr/progressBarStyle"
                android:layout_width="match_parent"
                android:layout_marginTop="10dp"
                android:layout_height="35dp"/>
            <requestFocus />

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/main_tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:visibility="visible"
        app:tabMode="scrollable"
        app:tabSelectedTextColor="@color/colorAccent" />

</android.support.design.widget.AppBarLayout>

Solution

  • I Found my Question answer It is problem because I was trying to override the theme Appcompat.light through searchAutoComplete.setDropDownBackgroundResource(android.R.color.white); So as soon as I removed this statement the border was removed.