我一直在使用:
style="@style/TextAppearance.AppCompat.SearchResult.Title"
在我的布局 xml 中,但这次我想通过 java 代码以编程方式设置文本样式。 但是这段代码:
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);
}
不编译。它说“无法解析符号‘TextAppearance’”。
最佳答案
您的依赖项中是否有 compile 'com.android.support:appcompat-v7:24.1.1'
? (在你的 build.gradle 文件中)
如果是这样,请尝试使用 android.support.v7.appcompat.R.style.TextAppearance_AppCompat_SearchResult_Title
作为资源 ID。
关于android - 将 TextView 的文本样式设置为 TextAppearance.Appcompat ...以编程方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38953565/