Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在Android中为NumberPicker设置textcolor时会发生NoSuchFieldException?_Android - Fatal编程技术网

为什么在Android中为NumberPicker设置textcolor时会发生NoSuchFieldException?

为什么在Android中为NumberPicker设置textcolor时会发生NoSuchFieldException?,android,Android,当我为NumberPicker设置文本颜色时 fun updateTextAttributes() { val typeface = Typeface.create(Typeface.DEFAULT, textStyle) try { val wheelPaint = wheelField.get(this) as Paint wheelPaint.textSize = textSize.toFloat()

当我为NumberPicker设置文本颜色时

fun updateTextAttributes() {
        val typeface = Typeface.create(Typeface.DEFAULT, textStyle)
        try {

            val wheelPaint = wheelField.get(this) as Paint
            wheelPaint.textSize = textSize.toFloat()
            wheelPaint.color = ContextCompat.getColor(context, R.color.member_center_text)
            wheelPaint.typeface = typeface



            for (i in 0 until childCount) {
                val child = getChildAt(i)
                if (child is EditText) {
                    child.setLinkTextColor(ContextCompat.getColor(context, R.color.member_center_text))
                    child.setHintTextColor(ContextCompat.getColor(context, R.color.member_center_text))
                    child.setTextColor(ContextCompat.getColorStateList(context, R.color.member_center_text))

                    child.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
                    child.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
                    child.typeface = typeface
                    invalidate()



                    break
                }
            }


        } catch (e: NoSuchFieldException) {
            Timber.d("TypeNumberPicker NoSuchFieldException:$e")
            // nothing to do, ignoring
        } catch (e: IllegalAccessException) {
            Timber.d("TypeNumberPicker IllegalAccessException:$e")
            // nothing to do, ignoring
        } catch (e: IllegalArgumentException) {
            Timber.d("TypeNumberPicker IllegalArgumentException:$e")
            // nothing to do, ignoring
        }
    }
它显示了

NoSuchFieldException:java.lang.NoSuchFieldException: No field mSelectorWheelPaint in class Landroid/widget/NumberPicker; (declaration of 'android.widget.NumberPicker' appears in /system/framework/framework.jar!classes3.dex)

我错过什么了吗?提前谢谢。

我想你应该这样做

EditText child = numberPicker.findViewById(android.R.id.numberpicker_input);  // Here numberPicker is object which you are using into your code. Replace it with your numberPicker
if (child != null) { // Rename child as meaningfull name
      child.setLinkTextColor(ContextCompat.getColor(context, R.color.member_center_text))
      child.setHintTextColor(ContextCompat.getColor(context, R.color.member_center_text))
      child.setTextColor(ContextCompat.getColorStateList(context, R.color.member_center_text))

      child.setTextSize(TypedValue.COMPLEX_UNIT_SP, pixelsToSp(context, textSize.toFloat()))
      child.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_VARIATION_NORMAL
      child.typeface = typeface
      invalidate()
}

您的代码中的mSelectorWheelPaint是什么?