如何以编程方式在 TextView 上设置 ?android:attr/textAppearanceListItem

m3h*_*hes 6 android textview

我正在尝试设置导航抽屉中自定义适配器中的文本视图的文本外观。我想让某些项目的文本比其他项目的文本小(例如谷歌音乐的导航抽屉)。所以我在 getView 方法中有一个 if 语句,我想对列表项使用默认的 android 样式。

我知道我可以执行以下操作:

textView.setTextAppearance(getContext(), android.R.style.TextAppearance_Small);
Run Code Online (Sandbox Code Playgroud)

但我找不到可以在 xml 中设置的 textAppearanceListItem 属性的 android.R.style 值:

android:textAppearance="?android:attr/textAppearanceListItem"
Run Code Online (Sandbox Code Playgroud)

Mec*_*cki 1

以下代码对我有用:

textView.setTextAppearance(getContext(), android.R.attr.textAppearanceListItem);
Run Code Online (Sandbox Code Playgroud)