Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView

后端 未结 8 1300
小鲜肉
小鲜肉 2020-11-29 21:19

I have a TextView with multiple ClickableSpans in it. When a ClickableSpan is pressed, I want it to change the color of its text.

I have tried setting a color state

8条回答
  •  無奈伤痛
    2020-11-29 22:20

    Place the java code as below :

    package com.synamegames.orbs;
    
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.TextView;
    
    public class CustomTouchListener implements View.OnTouchListener {     
    public boolean onTouch(View view, MotionEvent motionEvent) {
    
        switch(motionEvent.getAction()){            
            case MotionEvent.ACTION_DOWN:
             ((TextView) view).setTextColor(0x4F4F4F); 
                break;          
            case MotionEvent.ACTION_CANCEL:             
            case MotionEvent.ACTION_UP:
            ((TextView) view).setTextColor(0xCDCDCD);
                break;
        } 
    
        return false;   
    } 
    }
    

    In the above code specify wat color you want .

    Change the style .xml as you want.

    
    
    
    

    Try it out and say is this you want or something else . update me dude.

提交回复
热议问题