There is a shape (back.xml):

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:innerRadius="85dp" android:shape="ring" android:thickness="5dp" android:useLevel="false"> <solid android:color="#FF0000"> </solid> <size android:height="200dp" android:width="200dp"> </size> </shape> 

This shape is the background for TextView:

 <TextView android:id="@+id/fullscreen_content" android:layout_width="200dp" android:layout_height="200dp" android:keepScreenOn="true" android:textColor="#33b5e5" android:textStyle="bold" android:textSize="50sp" android:gravity="center" android:text="@string/dummy_content" android:layout_gravity="center" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:layout_marginTop="105dp" android:background="@drawable/back" /> 

As a result, it is necessary that the color of this ring (shape) around the text (textview) is constantly animated (smoothly) changed to random (randomcolor - decided).

This effect of changing color for shape is needed.

    1 answer 1

      ObjectAnimator objectAnimator = ObjectAnimator.ofInt(textView, "backgroundColor", Color.RED, Color.BLUE).setDuration(250); objectAnimator.setEvaluator(new ArgbEvaluator()); objectAnimator.start(); 

    Something like this. This code will change the background color with animation.

    • I, in fact, need to change not the background color of the textview, but the color Drawable, which is the background of the textview. Those. textView.setBackground (this.getResources (). getDrawable (R.drawable.back)); drawable = textView.getBackground (); And this Drawable object needs to smoothly change the color from the current to the random. - Levon
    • @Levon You need to create an attribute, for example, drawableBackColor, define it in Theme and substitute it into the Drawable description. Next, with that code on top of the textView, substitute the Drawable object, instead of "backgroundColor" write "drawableBackColor". It may help: 3 - Deadkenny
    • @Deadkenny Thank you so much! Everything worked out. Do without attributes. currentColor = randColor (); Drawable drawable = findViewById (R.id.fullscreen_content) .getBackground (); ObjectAnimator objectAnimator = ObjectAnimator.ofInt (drawable, "color", previousColor, currentColor) .setDuration (2000); objectAnimator.setEvaluator (new ArgbEvaluator ()); objectAnimator.start (); previousColor = currentColor; Since the colors are random, we remember the previous color in previousColor. - Levon
    • @Deadkenny wrote all this in timer.schedule (new RunTimer (), 0, 2000); for constant color change. It works too. But the feeling that podzhiraet memory (at least it grows in MemoryMonitor (Android Studio)). Would it be better to loop in a separate thread? - Levon
    • @Levon try ArgbEvaluator to create once in the Activity and reuse it. Most likely, he devours: 3 - Deadkenny