Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a strobe, flashing background using handlers
    primarykey
    data
    text
    <p>I am trying to make a strobe effect in the background of my app. I read that handlers would work the best, but I'm just not sure how to apply them. I saw <a href="https://stackoverflow.com/questions/12810705/how-do-i-make-a-layout-background-flashing-in-android">this post</a></p> <pre><code> public boolean onTouch(View v, MotionEvent event) { final int DELAY = 100; if(event.getAction() == MotionEvent.ACTION_UP) { RelativeLayout fondo = (RelativeLayout) findViewById(R.id.fondo); ColorDrawable f = new ColorDrawable(0xff00ff00); ColorDrawable f2 = new ColorDrawable(0xffff0000); ColorDrawable f3 = new ColorDrawable(0xff0000ff); ColorDrawable f4 = new ColorDrawable(0xff0000ff); AnimationDrawable a = new AnimationDrawable(); a.addFrame(f, DELAY); a.addFrame(f2, DELAY); a.addFrame(f3, DELAY); a.addFrame(f4, DELAY); a.setOneShot(false); fondo.setBackgroundDrawable(a); // This method is deprecated in API 16 // fondo.setBackground(a); // Use this method if you're using API 16 a.start(); } return true; } </code></pre> <p>What do I need to do to fix this? and is there a way to do this without handlers?</p> <pre><code> package com.example.converter; import android.app.Activity; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.ColorDrawable; import android.view.MotionEvent; import android.view.View; import android.widget.RelativeLayout; public class Savannah extends Activity { RelativeLayout r = (RelativeLayout) findViewById(R.layout.activity_savannah); r.setOnTouchListener=(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { final int DELAY = 100; if (event.getAction() == MotionEvent.ACTION_UP) { RelativeLayout fondo = (RelativeLayout) findViewById(R.layout.activity_savannah); ColorDrawable f = new ColorDrawable(0xff00ff00); ColorDrawable f2 = new ColorDrawable(0xffff0000); ColorDrawable f3 = new ColorDrawable(0xff0000ff); ColorDrawable f4 = new ColorDrawable(0xff0000ff); AnimationDrawable a = new AnimationDrawable(); a.addFrame(f, DELAY); a.addFrame(f2, DELAY); a.addFrame(f3, DELAY); a.addFrame(f4, DELAY); a.setOneShot(false); fondo.setBackgroundDrawable(a); // This method is deprecated // in API // 16 // fondo.setBackground(a); // Use this method if you're // using API 16 a.start(); } return true; } }); } </code></pre> <p>this is what i have, but the seontouch listener is flagging errors as is the ontouch view view motion event.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload