title: How to add a Lottie animation in Java programatically
body: <p>I tried to add Lottie Animation to Java (Android) programmatically, but I keep failing. I will show my code below I need to change from drawable to Lottie.</p>
  <p>This is the code for drawables:</p>
  <pre><code>if (status.equals(&quot;connect&quot;)) {
  
              vpnBtn.setBackgroundResource(R.drawable.but_connect_light);
              logTv.setTextColor(getResources().getColor(R.color.font_color));
  
          } else if (status.equals(&quot;connecting&quot;)) {
  
              vpnBtn.setBackgroundResource(R.drawable.but_connecting_dark);
              logTv.setTextColor(getResources().getColor(R.color.font_color));
  
          } else if (status.equals(&quot;connected&quot;)) {
  
              vpnBtn.setBackgroundResource(R.drawable.but_disconnect_dark);
              logTv.setTextColor(getResources().getColor(R.color.purple));
  
          } else if (status.equals(&quot;failed&quot;)) {
  
              vpnBtn.setBackgroundResource(R.drawable.but_connect_dark);
  
          }
  </code></pre>
  <p>This is the xml relating above</p>
  <pre><code>&lt;ImageView
          android:id=&quot;@+id/vpnBtn&quot;
          android:layout_alignParentBottom=&quot;true&quot;
          android:layout_gravity=&quot;center_horizontal&quot;
          android:tag=&quot;1&quot;
          android:layout_width=&quot;140dp&quot;
          android:layout_height=&quot;140dp&quot;
          android:background=&quot;@drawable/but_connect_light&quot;
          android:layout_centerHorizontal=&quot;true&quot;
          android:layout_marginBottom=&quot;50dp&quot;/&gt;
  </code></pre>