Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting TextView's text style to TextAppearance.Appcompat... programmatically

I have been using:

    style="@style/TextAppearance.AppCompat.SearchResult.Title"

in my layout xml, but this time i want to set text style programmatically from java code. But this code:

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        textView.setTextAppearance(R.style.TextAppearance.AppCompat.SearchResult.Title);
    } else {
        textView.setTextAppearance(this, R.style.TextAppearance.AppCompat.SearchResult.Title);
    }

doesn't compile. It says 'Cannot resolve symbol 'TextAppearance'.

like image 559
Євген Гарастович Avatar asked Aug 15 '16 10:08

Євген Гарастович


1 Answers

Do you have compile 'com.android.support:appcompat-v7:24.1.1' in your dependencies? (in your build.gradle file)

If so, try using android.support.v7.appcompat.R.style.TextAppearance_AppCompat_SearchResult_Title as resource id.

like image 122
Algar Avatar answered Sep 27 '22 17:09

Algar