T
T
Tsuzukeru2021-11-30 06:55:45
Android
Tsuzukeru, 2021-11-30 06:55:45

Why can't I get default values ​​for custom attributes?

Created a new custom attribute for custom view.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="InputTextViewWithHint">
        <attr name="android:textColorHint" format="color" />
    </declare-styleable>
</resources>


I get the value like this:

init {
    context.obtainStyledAttributes(attrs, R.styleable.InputTextViewWithHint).apply {
        try {
            val color = getColor(R.styleable.InputTextViewWithHint_android_textColorHint, 0)
            Log.i("getColor", "$color")
        }
        catch (throwable: Throwable) {
            logErrorIfDebug(throwable)
        } finally {
            recycle()
        }
    } 
}


When the attribute in xml is not set, 0 (default value) should come, but -7693911 comes. Why?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question