setTextAppearance在API级别23中已弃用 [英] setTextAppearance deprecated in API level 23

查看:149
本文介绍了setTextAppearance在API级别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.

TextViewCompat的来源

TextView(API23)的来源

这篇关于setTextAppearance在API级别23中已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆