setTextAppearance在API级别23中已弃用 [英] setTextAppearance deprecated in API level 23
问题描述
公共无效setTextAppearance(上下文上下文,int resId) 已在API级别1中添加
API级别23中不推荐使用此方法. 请改用setTextAppearance(int).
public void setTextAppearance (Context context, int resId) Added in API level 1
This method was deprecated in API level 23. Use setTextAppearance(int) instead.
我的问题:为什么不推荐使用它?为什么它不再需要Context
了?最重要的是,如何在旧版本中使用setTextAppearance(int resId)
?
My Question: Why it's been deprecated? Why it doesn't need Context
anymore? And most importantly, how to use setTextAppearance(int resId)
for older versions?
推荐答案
您可以从support/androidX库中使用TextViewCompat
:
You can use TextViewCompat
from the support/androidX library:
import android.support.v4.widget.TextViewCompat // for support-library
import androidx.core.widget.TextViewCompat // for androidX library
// ...
TextViewCompat.setTextAppearance(view, resId)
内部,它从API<的视图(view.getContext()
)中获取上下文. 23.
Internally it gets the context from the view (view.getContext()
) on API < 23.
这篇关于setTextAppearance在API级别23中已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!