Android SDK 22 - SearchView rendering problems

Solution 1:

Edit

Change your android version on your designer preview into your current version depend on your Manifest. rendering problem caused your designer preview used higher API level than your current android API level.


It should work

Just change the api 22 to 21 in android xml layout

enter image description here

Solution 2:

I voted up Davide comments. Error means searchIcon can not be null (why?).

This works to compile at Studio with api 22, but forces you to select an icon. The example is one of 2 defaults at android (none as cool as searchview default), you can always have your custom one...

Here the snippet.

        <SearchView
        android:id="@+id/searchBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:searchIcon="@android:drawable/ic_search_category_default"
        tools:ignore="UnusedAttribute" />

Solution 3:

Found this in the source. It's the dereference of a that fails in the evaluation.

    final TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.SearchView, defStyleAttr, defStyleRes);

    [...]

    // Prior to L MR1, the search hint icon defaulted to searchIcon. If the
    // style does not have an explicit value set, fall back to that.
    if (a.hasValueOrEmpty(R.styleable.SearchView_searchHintIcon)) {
        mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchHintIcon);
    } else {
        mSearchHintIcon = a.getDrawable(R.styleable.SearchView_searchIcon);
    }

Try setting the styled attributes?