i meet a issue on Android , i can't set the background color ,  can
anyone help me? thanks in advance.

set a string to the textview, and use setOnTouchListener to capture
touch event, when receive MotionEvent.ACTION_UP event. set the
background color to 0xFFFF0000(red), when receive
MotionEvent.ACTION_DOWN event. set the background color to 0xFF0000FF
(blue)

my codes as below:
textView.setText(string);
final SpannableString str = new SpannableString(string);

textView.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
                int eventaction = event.getAction();

                switch (eventaction) {
                case MotionEvent.ACTION_UP:
                                str.setSpan(new 
BackgroundColorSpan(0xFFFF0000), 0, string.length
(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                                textView.invalidate();
                                return true;

                case MotionEvent.ACTION_DOWN:
                                str.setSpan(new 
BackgroundColorSpan(0xFF0000FF), 0, string.length
(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                                textView.invalidate();
                                return true;

                        default:
                                return v.onTouchEvent(event);
                }
        }
});

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to