I found the this link, which says how I could make a glow effect on my ImageButton . Therefore, whenever the user clicks the ImageButton button, the onTouchEvent() function is onTouchEvent() and there I call the setImageBitmap() function. The problem is that this function ( setImageBitmap() ) does not seem to have any effect.
What works:
1) So far I have expanded ImageButton as below
// Pen.java public class Pen extends ImageButton { public Pen(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onTouchEvent(MotionEvent event) { System.out.println("Now I am setting Pen"); return true; } }
Then inside the Activity create a Pen instance (custom ImageButton ), define setGlow() and call setImageBitmap() from the Pen instance.
//MainActivity.java
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Pen myImgbutton; myImgbutton = (Pen) findViewById(R.id.pen); myImgbutton.setImageBitmap(setGlow(R.drawable.pen)); } } public Bitmap setGlow(int resourceId) { ...... }
What does not work:
1) All of the above (ImageButton extension in android), but this time I'm calling setImageBitmap from inside onTouchEvent (). For this case, I define the setGlow function inside Pen.java
// Pen.java public class Pen extends ImageButton { public Pen(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onTouchEvent(MotionEvent event) { System.out.println("Now I am setting Pen"); // Here I say to apply the glow effect to the image setImageBitmap(setGlow(R.drawable.pen)); return true; } public Bitmap setGlow(int resourceId) { .... } }
Then in the xml file I:
..... <com.example.testsetimagebmp.Pen android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/pen" android:background="@drawable/pen" /> ....
Finally, in MainActivity
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }
android bitmap android-bitmap android-drawable bitmapimage
pokche
source share