0

I am creating a selector with spannable string of textview with the help of this stackoverflow link (Change the text color of a single ClickableSpan when pressed without affecting other ClickableSpans in the same TextView),

it is working fine on all android version except android-M, i am not able to detect why, so please assist me guys.

Basically my view is like this one, https://drive.google.com/file/d/0BwkVxZWl7VcEVkFTQVRNbE9sLTA/view?usp=sharing, i want a selector on Register Now, but that must not affect the rest of text and it all must be with single text view or spannable

import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import cl.dummy.R;
import cl.dummy.utility.spannablee.LinkTouchMovementMethod;
import cl.dummy.utility.spannablee.TouchableSpan;


public class Login extends AppCombatActivity 
{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

                init();
    }

    private final void init()
    {
        final TextView myTextView =  GeneralFunctions.findViewByIdAndCast(this, R.id.login_tv_noAccount);
        final SpannableString mySpannable = new SpannableString(myTextView.getText().toString());
        final TouchableSpan touchableSpan = new TouchableSpan(ContextCompat.getColor(this, R.color.color60),ContextCompat.getColor(this, R.color.colorBlue),Color.TRANSPARENT) {
            @Override
            public void onClick(View textView) {
                GeneralFunctions.simpleMoveToNextActivity(Register.class, Login.this,null);
            }
        };

                myTextView.setMovementMethod(new LinkTouchMovementMethod());
                myTextView.setHighlightColor(ContextCompat.getColor(Login.this, android.R.color.transparent));

                mySpannable.setSpan(touchableSpan, GeneralFunctions.getText(myTextView).indexOf("Register"), GeneralFunctions.getText(myTextView).length(), 0);
                myTextView.setText(mySpannable, TextView.BufferType.SPANNABLE);
    }
}
Community
  • 1
  • 1
Reprator
  • 2,859
  • 2
  • 32
  • 55
  • what selector are you talking about? selectors are used in `ListView`s, see `ListView#setSelector` method but here i dont see any list view – pskink Jan 12 '16 at 09:38
  • @pskink, i am talking about the selector on spannable, means when text is selected,it's color gets changed but not full text only of select text – Reprator Jan 12 '16 at 10:42
  • sorry, still have no idea what you mean – pskink Jan 12 '16 at 10:45
  • @pskink, i had uploaded a file here https://drive.google.com/file/d/0BwkVxZWl7VcEVkFTQVRNbE9sLTA/view?usp=sharing, i want a selector on Register Now, but that must not affect the rest of text and it all must be with single text view and spannable – Reprator Jan 13 '16 at 05:29
  • I tested it on M and everything work's fine. I don't use `setHighlightColor` and I see that you use Color.TRANSPARENT as TouchableSpan parameter. OFFTOP: I recommend you use ButterKnife plugin to view injections or even Android Annotations to much more stuff ;) – wrozwad Feb 04 '16 at 13:30
  • @sosite, if i don't you the 'setHighlightColor' then a background occurs, how can i remove it – Reprator Feb 05 '16 at 05:17
  • @VikramSingh, you can try to `setFocusable(false)`, `setClickable(false)` and `setLongClickable(false)` after you `setMovementMethod()` – wrozwad Feb 05 '16 at 10:22
  • @sosite, thank you it worked – Reprator Feb 05 '16 at 12:11

1 Answers1

1

i had solved the above issue by converting the textview into button and it works well but i don't know the reason as why it was not working with textview in android M

Reprator
  • 2,859
  • 2
  • 32
  • 55
  • @TheGreat0004, it works but i wanted to know the answer as why it is not working with textview on android M and working with buttons – Reprator Jan 13 '16 at 07:23