android - 在 API 级别 23 中不推荐使用 setTextAppearance

标签 android deprecated

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)

最佳答案

您可以使用 support/androidX 库中的 TextViewCompat:

    import android.support.v4.widget.TextViewCompat // for support-library
    import androidx.core.widget.TextViewCompat      // for androidX library

    // ...

    TextViewCompat.setTextAppearance(view, resId)

在内部,它从 API < 23 上的 View (view.getContext()) 获取上下文。

Source for TextViewCompat

Source for TextView (API23)

关于android - 在 API 级别 23 中不推荐使用 setTextAppearance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33581814/

相关文章:

java - 单击 ImageView 时开始新视频

具有优先顺序的Android MultiSelectListPreference

java.net.URLEncoder.encode(String) 已弃用,我应该改用什么?

java - 为什么不推荐使用 JButton.enable?

java - 将 Java Applet 替换为另一种技术

Android 推特登录错误

android - OpenGL 渲染器 : Bitmap too large to be uploaded into a texture in android titanium

java - 仅混淆 Android 中的一个类文件

ruby-on-rails - Rails 3.1.0 Assets 文件夹未呈现:不建议使用Sprockets::Environment#static_root

java - session.getCurrentSession().createCriteria(MyClass.class) 已弃用如何使用 .addOrder() 现在