4

There are similar questions on stackoverflow, however they answer the question of "how to highlight onclick" not ontouch

Is there a way to (for example) set background color of the clickablespan ontouch?

frankish
  • 6,738
  • 9
  • 49
  • 100
  • 1
    Capture the touch event coordinates. Define range-wise behaviour as per your layout. CAUTION: Capturing touch-event may take a lot of CPU usage! Please be SURE if you really want this kind of implementation in your app. – Kunal S. Kushwah Jun 05 '13 at 08:44
  • @KunalS.Kushwah, u could post this as an answer.. – amalBit Jun 05 '13 at 08:55
  • OK! Actually I use LG-P970. It has a pre-built software which shows screen captures (probably developed by LG itself). I was thinking of implementing it too. :) – Kunal S. Kushwah Jun 05 '13 at 09:00

2 Answers2

0

You can achieve this by following the patters of touches on the device--- Capture the touch event coordinates. Define range-wise behaviour as per your layout. CAUTION: Capturing touch-event may take a lot of CPU usage! Please be SURE if you really want this kind of implementation in your app.

Kunal S. Kushwah
  • 883
  • 1
  • 8
  • 19
  • I need to use it for a good user-action-response. I want to do this in a twitter application, where you see the highlight when you touch down on a hashtag or username. Can't there be any solution? – frankish Jun 05 '13 at 09:07
  • From what i can get in this context-- 1. there would be too much pressure on cpu, and 2. If the purpose is to notify user VISUALLY about a hash-tag, there can be simpler things which you can do in your layout directly. Why bother about capturing ACTION-RESPONSE? Also, a "highlight" thing is more suitable for a web-site kind of view,but not for an action-oriented environment like android app. – Kunal S. Kushwah Jun 05 '13 at 09:11
  • For example, you like the way Google Play Market does when you touch one of the buttons on the first page of the Market, right? I want the similar feel. – frankish Jun 05 '13 at 09:16
  • It is NOT the touch-event capturing in Google Play. It is a click-event capture! If you need that a button should get 'highlighted' when clicked, well then here is a link for you-- http://stackoverflow.com/questions/7803430/how-to-change-background-image-of-button-when-clicked-focused – Kunal S. Kushwah Jun 05 '13 at 09:20
  • If it helped solving your problem, marking the answer wont hurt i suppose! :) – Kunal S. Kushwah Jun 05 '13 at 09:30
  • Click event occurs after you release your finger. If it is highlighted before you release your finger, it is a touchdown/mousedown event. (I am already using similar solution for my buttons.) – frankish Jun 05 '13 at 10:05
  • That' what the link says. You can define any highlighting procedure for all states-- normal, focussed, pressed, and a combination of focussed and pressed. – Kunal S. Kushwah Jun 05 '13 at 10:10
  • The problem is, i can not define focussed, pressed state for ClickableSpan that can be set on TextView – frankish Jun 05 '13 at 10:16
  • i was looking at the ClickSpan documentation-- http://developer.android.com/reference/android/text/style/ClickableSpan.html won't updateDrawState(TextPaint ds) function help you? You can override it and do the required thing! – Kunal S. Kushwah Jun 05 '13 at 10:18
  • I need to get the state (pressed?) of the span in that function, so i could make the changes. – frankish Jun 05 '13 at 10:22
  • check this link -- http://stackoverflow.com/questions/4282975/can-i-change-the-look-and-feel-of-the-clickablespan – Kunal S. Kushwah Jun 05 '13 at 10:25
  • It changes the color but not only onpress – frankish Jun 05 '13 at 10:31
0

For highlighting you can not change the background of ClickableSpan but you can change the Text color and Style to make bold or Italic to highlight.

<string name = "descMsg">Tap &lt;FONT COLOR=\"#E22882\">"&lt;i>here&lt;/i>&lt;/FONT> to launch the app.</string>

You can use this in string.xml with HTML tag.

Hope this will help you..:)

Vishesh Chandra
  • 6,951
  • 6
  • 35
  • 38
  • How can i do it on the "press" of ClickableSpan? – frankish Jun 05 '13 at 10:17
  • Please follow [this link](http://stackoverflow.com/questions/15851655/android-change-the-background-color-of-a-clickablespan-when-clicked?answertab=active#tab-top) for text color change onClick – Vishesh Chandra Jun 05 '13 at 11:21
  • I need onPress which should only change the color while the finger is on that span (not after releasing the finger) – frankish Jun 05 '13 at 11:56
  • @frankish - Were you able to solve this issue. I am in a similar situation and trying to do change the color when user focus a text in a spannable string. So far i found out , the only way i can do it is if use a separate textview for that and set the state properties. But i want to do it on Spannable. – aNoviceGuy Nov 01 '13 at 23:10
  • @aNoviceGuy I gave up; I use ClickableSpan and I color it but I do not change anything related to onTouch/onClick/Highlight etc.. – frankish Nov 02 '13 at 20:58