selector with spanable not working on android M but working fine on below M

时间秒杀一切 提交于 2019-12-02 18:26:29

问题


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);
    }
}

回答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



来源:https://stackoverflow.com/questions/34737514/selector-with-spanable-not-working-on-android-m-but-working-fine-on-below-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!