Java Code Examples for android.widget.AutoCompleteTextView#setDropDownBackgroundDrawable()

The following examples show how to use android.widget.AutoCompleteTextView#setDropDownBackgroundDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchActivity.java    From OpenHub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView =
            (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false);
    if (isInputMode) {
        MenuItemCompat.expandActionView(searchItem);
    } else {
        MenuItemCompat.collapseActionView(searchItem);
    }
    MenuItemCompat.setOnActionExpandListener(searchItem, this);

    AutoCompleteTextView autoCompleteTextView = searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    autoCompleteTextView.setThreshold(0);
    autoCompleteTextView.setAdapter(new ArrayAdapter<>(this,
            R.layout.layout_item_simple_list, mPresenter.getSearchRecordList()));
    autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity())));
    autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
        onQueryTextSubmit(parent.getAdapter().getItem(position).toString());
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example 2
Source File: ViewUtil.java    From MDPreference with Apache License 2.0 5 votes vote down vote up
/**
 * Apply any AutoCompleteTextView style attributes to a view.
 * @param v
 * @param attrs
 * @param defStyleAttr
 * @param defStyleRes
 */
private static void applyStyle(AutoCompleteTextView v,  AttributeSet attrs, int defStyleAttr, int defStyleRes){
    TypedArray a = v.getContext().obtainStyledAttributes(attrs, R.styleable.AutoCompleteTextView, defStyleAttr, defStyleRes);

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        if(attr == R.styleable.AutoCompleteTextView_android_completionHint)
            v.setCompletionHint(a.getString(attr));
        else if(attr == R.styleable.AutoCompleteTextView_android_completionThreshold)
            v.setThreshold(a.getInteger(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownAnchor)
            v.setDropDownAnchor(a.getResourceId(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHeight)
            v.setDropDownHeight(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownWidth)
            v.setDropDownWidth(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHorizontalOffset)
            v.setDropDownHorizontalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownVerticalOffset)
            v.setDropDownVerticalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_popupBackground)
            v.setDropDownBackgroundDrawable(a.getDrawable(attr));
    }
    a.recycle();
}
 
Example 3
Source File: DropdownMenuEndIconDelegate.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void setPopupBackground(@NonNull AutoCompleteTextView editText) {
  if (IS_LOLLIPOP) {
    int boxBackgroundMode = textInputLayout.getBoxBackgroundMode();
    if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_OUTLINE) {
      editText.setDropDownBackgroundDrawable(outlinedPopupBackground);
    } else if (boxBackgroundMode == TextInputLayout.BOX_BACKGROUND_FILLED) {
      editText.setDropDownBackgroundDrawable(filledPopupBackground);
    }
  }
}
 
Example 4
Source File: ViewUtil.java    From material with Apache License 2.0 5 votes vote down vote up
/**
 * Apply any AutoCompleteTextView style attributes to a view.
 * @param v
 * @param attrs
 * @param defStyleAttr
 * @param defStyleRes
 */
private static void applyStyle(AutoCompleteTextView v,  AttributeSet attrs, int defStyleAttr, int defStyleRes){
    TypedArray a = v.getContext().obtainStyledAttributes(attrs, R.styleable.AutoCompleteTextView, defStyleAttr, defStyleRes);

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        if(attr == R.styleable.AutoCompleteTextView_android_completionHint)
            v.setCompletionHint(a.getString(attr));
        else if(attr == R.styleable.AutoCompleteTextView_android_completionThreshold)
            v.setThreshold(a.getInteger(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownAnchor)
            v.setDropDownAnchor(a.getResourceId(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHeight)
            v.setDropDownHeight(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownWidth)
            v.setDropDownWidth(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHorizontalOffset)
            v.setDropDownHorizontalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownVerticalOffset)
            v.setDropDownVerticalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_popupBackground)
            v.setDropDownBackgroundDrawable(a.getDrawable(attr));
    }
    a.recycle();
}