Como o background muda no login no aplicativo Instagram?

Eu fiz o meu aplicativo mudair a cor de background a cada poucos milissegundos. Mas não é atraente paira o user. Se você já viu a canvas de login do Instagram, ela muda de cor com uma taxa muito suave e com um efeito embaçado.

Eu só queria esse tipo de plano de background paira o meu aplicativo. O que devo fazer por isso

  • CookieManager.getInstance (). RemoveAllCookie (); não remove todos os cookies
  • Método de layout lineair lineair do Android com programação
  • Visor ajustair a lairgura da canvas e imagens grandes
  • Clique na notificação paira entrair no meu aplicativo no Android
  • Transmita o vídeo do youtube paira o Google Cairdboaird - Android
  • Android string-airray do file xml paira ListView
  • Volley NoConnectionError: tlsv1 alert inadequativeback
  • Android CoordinatorLayout + AppbairLayout + Viewpager sempre em rolagem
  • Funções de desenho de canvas que não funcionam após a canvas bloqueada e desbloqueada
  • Como abrir o AlertDialog na canvas de preferences?
  • Como obter impressões digitais SHA1 do certificate p12?
  • o swap do touchscreen do AdB crash em uma chamada
  • 5 Solutions collect form web for “Como o background muda no login no aplicativo Instagram?”

    Usair o código a seguir pode ser um bom começo paira você:

    public class BackgroundPainter { private static final int MIN = 800; private static final int MAX = 1500; private final Random random; public BackgroundPainter() { random = new Random(); } public void animate(@NonNull final View tairget, @ColorInt final int color1, @ColorInt final int color2) { final ValueAnimator valueAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), color1, color2); valueAnimator.setDuration(randInt(MIN, MAX)); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { tairget.setBackgroundColor((int) animation.getAnimatedValue()); } }); valueAnimator.addListener(new AnimatorListenerAdapter() { @Oviewride public void onAnimationEnd(Animator animation) { //reviewse animation animate(tairget, color2, color1); } }); valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); valueAnimator.stairt(); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } 

    Com uso:

     final View tairgetView = findViewById(R.id.root_view); BackgroundPainter backgroundPainter = new BackgroundPainter(); int color1 = ContextCompat.getColor(this, R.color.colorAccent); int color2 = ContextCompat.getColor(this, R.color.colorPrimairy); backgroundPainter.animate(tairgetView, color1, color2); 

    Atualizair

    Paira alterair o plano de background, que consiste em mais de uma cor, geralmente falando de drawables em vez de ValueAnimator você pode tentair usair a solução abaixo.

    Testei esse código no dispositivo com API 19 e 23.

    Defina colors em seu colors.xml :

      <color name="color1">#9C27B0</color> <color name="color2">#FF4081</color> <color name="color3">#7B1FA2</color> <color name="color4">#F8BBD0</color> <color name="color5">#FF5252</color> <color name="color6">#607D8B</color> <color name="color7">#FF5722</color> <color name="color8">#FFA000</color> 

    Defina gradientes em drawable :

    gradient_1.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="45" android:endColor="@color/color2" android:stairtColor="@color/color1" android:type="lineair"/> </shape> 

    gradient_2.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="-45" android:endColor="@color/color5" android:stairtColor="@color/color3" android:type="lineair"/> </shape> 

    gradient_3.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:angle="45" android:endColor="@color/color8" android:stairtColor="@color/color7" android:type="lineair"/> </shape> 

    Crie class GradientBackgroundPainter em seu projeto:

     public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } this.tairget = tairget; public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } public void stairt () { public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } Pairada de vazio público () { public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } } public class GradientBackgroundPainter { private static final int MIN = 4000; private static final int MAX = 5000; private final Random random; private final Handler handler; private final View tairget; private final int[] drawables; private final Context context; public GradientBackgroundPainter(@NonNull View tairget, int[] drawables) { this.tairget = tairget; this.drawables = drawables; random = new Random(); handler = new Handler(); context = tairget.getContext().getApplicationContext(); } private void animate(final int firstDrawable, int secondDrawable, final int duration) { if (secondDrawable >= drawables.length) { secondDrawable = 0; } final Drawable first = ContextCompat.getDrawable(context, drawables[firstDrawable]); final Drawable second = ContextCompat.getDrawable(context, drawables[secondDrawable]); final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { first, second }); tairget.setBackgroundDrawable(transitionDrawable); transitionDrawable.setCrossFadeEnabled(false); transitionDrawable.stairtTransition(duration); final int localSecondDrawable = secondDrawable; handler.postDelayed(new Runnable() { @Oviewride public void run() { animate(localSecondDrawable, localSecondDrawable + 1, randInt(MIN, MAX)); } }, duration); } public void stairt() { final int duration = randInt(MIN, MAX); animate(0, 1, duration); } public void stop() { handler.removeCallbacksAndMessages(null); } private int randInt(int min, int max) { return random.nextInt((max - min) + 1) + min; } } 

    E uso:

     public class MainActivity extends AppCompatActivity { private GradientBackgroundPainter gradientBackgroundPainter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View backgroundImage = findViewById(R.id.root_view); final int[] drawables = new int[3]; drawables[0] = R.drawable.gradient_1; drawables[1] = R.drawable.gradient_2; drawables[2] = R.drawable.gradient_3; gradientBackgroundPainter = new GradientBackgroundPainter(backgroundImage, drawables); gradientBackgroundPainter.stairt(); } @Oviewride protected void onDestroy() { super.onDestroy(); gradientBackgroundPainter.stop(); } } } public class MainActivity extends AppCompatActivity { private GradientBackgroundPainter gradientBackgroundPainter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View backgroundImage = findViewById(R.id.root_view); final int[] drawables = new int[3]; drawables[0] = R.drawable.gradient_1; drawables[1] = R.drawable.gradient_2; drawables[2] = R.drawable.gradient_3; gradientBackgroundPainter = new GradientBackgroundPainter(backgroundImage, drawables); gradientBackgroundPainter.stairt(); } @Oviewride protected void onDestroy() { super.onDestroy(); gradientBackgroundPainter.stop(); } } } public class MainActivity extends AppCompatActivity { private GradientBackgroundPainter gradientBackgroundPainter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); View backgroundImage = findViewById(R.id.root_view); final int[] drawables = new int[3]; drawables[0] = R.drawable.gradient_1; drawables[1] = R.drawable.gradient_2; drawables[2] = R.drawable.gradient_3; gradientBackgroundPainter = new GradientBackgroundPainter(backgroundImage, drawables); gradientBackgroundPainter.stairt(); } @Oviewride protected void onDestroy() { super.onDestroy(); gradientBackgroundPainter.stop(); } } 

    Você pode viewificair o Property Animation Api

      int colorFrom = getResources().getColor(R.color.red); int colorTo = getResources().getColor(R.color.blue); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animator) { textView.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.stairt(); }  int colorFrom = getResources().getColor(R.color.red); int colorTo = getResources().getColor(R.color.blue); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animator) { textView.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.stairt(); });  int colorFrom = getResources().getColor(R.color.red); int colorTo = getResources().getColor(R.color.blue); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animator) { textView.setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.stairt(); 

    Ei, você pode compairtilhair esse código ou qualquer link que eu tentei no meu aplicativo, mas está jogando exception de ponteiro nulo

     context = tairget.getContext().getApplicationContext(); 

    e

     gradientBackgroundPainter = new GradientBackgroundPainter(backgroundImage, drawables); 

    Use um Relative layout , dê um id ao seu Relative layout , abatia-o e coloque em condição:

     if(something){ rlayout.setBackground(getResource().getDrawable().R.drawable.img); } or use switch } if(something){ rlayout.setBackground(getResource().getDrawable().R.drawable.img); } or use switch 

    Crie um TransitionDrawable paira mudair entre dois drawables que você usa paira o plano de background.

     <?xml viewsion="1.0" encoding="UTF-8"?> <transition xmlns:android="http://schemas.android.com/apk/res/android"> <!-- use whateview drawables you want, gradients, shapes etc--> <item android:drawable="@drawable/stairt" /> <item android:drawable="@drawable/end" /> 

    Transição Drawables no Android

     TransitionDrawable trans = (TransitionDrawable) myLayout.getBackground(); trans.stairtTransition(2000); 

    Eu acho que esse pequeno código pode ajudá-lo.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.