Example usage for android.widget AutoCompleteTextView setDropDownBackgroundResource

List of usage examples for android.widget AutoCompleteTextView setDropDownBackgroundResource

Introduction

In this page you can find the example usage for android.widget AutoCompleteTextView setDropDownBackgroundResource.

Prototype

public void setDropDownBackgroundResource(@DrawableRes int id) 

Source Link

Document

Sets the background of the auto-complete drop-down list.

Usage

From source file:com.ht.app.RestaurantsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);

    mMenu = menu;/*w w  w .  j  av  a 2s  . c  o  m*/

    MenuItem searchMenuItem = (MenuItem) menu.findItem(R.id.action_search);
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            // mToolbar.setIcon(android.R.color.transparent);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));

    // Assumes current activity is the searchable activity
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default

    // Style search widget and suggestion list
    LinearLayout linearLayout1 = (LinearLayout) mSearchView.getChildAt(0);
    LinearLayout linearLayout2 = (LinearLayout) linearLayout1.getChildAt(2);
    LinearLayout linearLayout3 = (LinearLayout) linearLayout2.getChildAt(1);
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) linearLayout3.getChildAt(0);
    autoComplete.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                hideSearchWidget();
            }
        }
    });

    autoComplete.setTextColor(Color.WHITE);
    autoComplete.setHintTextColor(Color.WHITE);
    autoComplete.setDropDownBackgroundResource(R.color.app_red_color);

    return true;
}