Как изменить цвет текста предпочтительной категории в Android?

Вам нужно использовать __repr__. Это стандартная функция, такая как __init__. Например:

class Foobar():
    """This will create Foobar type object."""

    def __init__(self):
        print "Foobar object is created."

    def __repr__(self):
        return "Type what do you want to see here."

a = Foobar()

print a
28
задан Michael Eilers Smith 23 July 2012 в 06:16
поделиться

1 ответ

Вдохновленный ответом @AliSh, но я должен был только изменить цвет один Preference текстовый объект. Так, для всех парней Kotlin там:

class TextColorPreference : Preference {

    constructor(context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs)

    constructor(
        context: Context, attrs: AttributeSet,
        defStyle: Int
    ) : super(context, attrs, defStyle)

    override fun onBindViewHolder(holder: PreferenceViewHolder?) {
        super.onBindViewHolder(holder)

        context?.let {
            (holder?.findViewById(android.R.id.title) as? TextView)?.setTextColor(
                ContextCompat.getColor(
                    it,
                    R.color.colorPrimary
                )
            )
        }
    }
}

И затем помещенный это в Ваш xml/prefs.xml:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

    <this.should.be.your.package.TextColorPreference
        android:id="@+id/settings_logout"
        android:key="@string/prefs_key_logout"
        android:title="@string/settings_logout" />
</PreferenceScreen>
1
ответ дан 27 November 2019 в 22:56
поделиться
Другие вопросы по тегам:

Похожие вопросы: