Android SDK 22 - SearchView rendering problems

眉间皱痕 提交于 2019-11-26 16:42:13

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

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

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?

Try changing API level to higher Rendering error will not be there.

It will resolve rendering issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!