0

I have been trying to animate a spannablestringbuilder. However, I get this message from the Devices Logcat: "PropertyValuesHolder﹕ Method setAlpha() with type float not found on target class class".

Any ideas of how to animate a pure string at all?

Code of what I have been doing:

   private static void fadeEnhancedText(Context context,TextView labText, TextView labEnchangedText,
                                         int defaultColor) {
        //animation add objectanimation
        SpannableStringBuilder mSpannableStringBuilder=
                new SpannableStringBuilder(labEnchangedText
                        .getText().toString());
        mSpannableStringBuilder.setSpan(mForegroundColorSpan, mMatcher.start(),
                mMatcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        labText.setText(labEnchangedText.getText().toString());
        labText.setVisibility(View.GONE);
        //TODO spannable problem fader doesn't work fully
        labEnchangedText.setText(mSpannableStringBuilder, TextView.BufferType.SPANNABLE);
        mAnimationSet.play(fadeIn(labEnchangedText,mSpannableStringBuilder)).
                after(fadeOut(labEnchangedText,
                labText,
                defaultColor,mSpannableStringBuilder));
       mAnimationSet.start();
    }

    private static ObjectAnimator fadeIn(TextView textView, SpannableStringBuilder spannableStringBuilder)
    {
        ObjectAnimator animation = ObjectAnimator.ofFloat(spannableStringBuilder.getSpans(mMatcher.start(),
                mMatcher.end(),textView.getClass()), "alpha",0f,1f);
        animation.setDuration(300);
        return animation;

    }

    private static ObjectAnimator fadeOut(final TextView textView, final TextView currentView, final int defaultColor,
                                          final SpannableStringBuilder spannableStringBuilder)
    {
        //textView.setTextColor(Color.rgb(177, 24, 46));
        ObjectAnimator animation = ObjectAnimator.ofFloat(spannableStringBuilder.getSpans(mMatcher.start(),
                mMatcher.end(),textView.getClass()), "alpha",1f,0f);
        animation.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                textView.setTextColor(defaultColor);
                currentView.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animation.setRepeatCount(4);
        animation.setDuration(300);
        return animation;

    }
Khiem-Kim Ho Xuan
  • 1,301
  • 1
  • 22
  • 45

1 Answers1

1

TextView, the type returned for the spans in the call to getSpans (you specify the type as TextView), does not have a setAlpha method (nor a getAlpha method). Also, I'm not sure how ObjectAnimator likes arrays, but I haven't tried it.

Have a look at Android Transparent TextView? for TextView transparency.

It might also be possible to use HTML to style the text: How to display HTML in TextView? or see the string resources guide: http://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML

Community
  • 1
  • 1
Sardtok
  • 449
  • 7
  • 18