add TouchListener to Drawable

I want to make a Drawable touchable for a component I am creating, does anyone know how to do that?

final Drawable selected = backgroundSelected;

selected.setBounds(0, 0, 20, 90);
selected.draw(canvas);
canvas.save();


Asked by: Emily109 | Posted: 24-01-2022






Answer 1

Solved it by using an onTouch event, and then checking the coordinates of the touch against the coordinates of the Drawable.

Answered by: Richard446 | Posted: 25-02-2022



Similar questions

android - Touchlistener on widget ?

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { int imageNum = (new java.util.Random().nextInt(IMAGES.length)); RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.main); remoteView.setImageViewResource(R.id.image, IMAGES[imageNum]); appWidgetManager.updateAppWidget(...


android - Disabling touchlistener working in one context but not in another context

i have an application which has this layout. now when the user touches some button and releases his finger from that button, the key is entered into the textbox. mean while it also pronounces that letter to the user. saying "B is entered". so it is during ACTION_UP. during this event handling i need to prevent touch events even if by accident the user touches...


android - How to consume child view's touch event in parent view's touchlistener?

In my application I want to get the touch event of all child view's in my parent view's onTouchListener but I could not get this. Example: In my activity's view I have one frame layout which has some buttons and edittexts in it. So whenever I touch buttons or edit text I want to get this touch event in framlayout's onTouchListeners. Here is...


android - In webview, override TouchListener

I use webview in android and need to recognize is it scroll or not when scroll webview, hide my option tab and stop scrolling, set visible webview. www.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if(event.getAction() == MotionEvent.ACTION_UP) ...


java - AndEngine how works the TouchListener

im trying to programming a little game. So and i have a little D-Pad and i want that the method onSceneTouchEvent run my method while i touch the screen. But the programm call the method only when im moveing my finger not when im touching the display.


android - ImageView and touchListener

I try to make an imageview clickable. Actually it is clickable, so that I can call an Intent after the user touches the imageview. But I am struggeling to change the image on touch. I want the following: Default (no touch) : Image1 User touches the imageview: change to image2 User moves with finger out of imageview : change back to Image1 (without calling Intent) User unto...


Android : How to use TouchListener to react to movement across button

I'm new to Android development and I was wondering if there is a way to add a TouchListener (or any event listener) to a button such that it reacts to movement across it's area. For instance if I have a button in the middle of the screen and I start swiping from the top it should react when my finger reaches the button area. This is the code I thought would do it private OnTouchListener tLis =...


Android ListView TouchListener called on scroll

In my project I have a ListView which has a touchListener in getView method from adapter for each view. My problem is that the touchListener activates when I scroll the list. How could I disable the touch when the user scrolls the list, regarding that the listener is set on getView() method? Thanks ...


java - TouchListener is overriding a ClickListener

I have a RelativeLayout with a SlidingDrawer. I am using the drawer as a menu. When you click on an item in the drawer, it adds a ImageView to the RelativeLayout. I'd like to be able to move the ImageView around. I am using a ClickListener for each menu item in the SlidingDrawer. This part works great. For the objects I add to the RelativeView, I set a TouchListener. For the ImageView being added, I set a Tou...


android - When using touchListener in activity how can we get information back to the activity from the listener?

I have an activity in which I have an ImageView and a SeekBar. I registered a listener with imageview1.setOnTouchListener(mylistener) for the ImageView(mylistner is a class). I get the motion events in onTouch method in my listener. I want the program to hide the SeekBar when I touch the Image View. All the Tutorials I watched show how the listener gets the event from the source. But what I am looking for is sending the da...






Still can't find your answer? Check out these communities...



Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android



top