具有spanable的选择器在android M上不起作用,但在m以下 [英] selector with spanable not working on android M but working fine on below M

查看:105
本文介绍了具有spanable的选择器在android M上不起作用,但在m以下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过这个stackoverflow链接创建一个具有文本视图可扩展字符串的选择器 (更改按下时单击一个ClickableSpan,而不会影响同一TextView中的其他ClickableSpans ),

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),

在除android-M之外的所有android版本上都可以正常工作,我无法检测到原因,所以请协助我.

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

我的观点基本上就是这样, https://drive .google.com/file/d/0BwkVxZWl7VcEVkFTQVRNbE9sLTA/view?usp = sharing ,我想在立即注册"上使用一个选择器,但该选择器不得影响其余文本,并且所有选择器都必须具有单个文本视图或可跨度/p>

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

推荐答案

我已经通过将textview转换为button解决了上述问题,并且效果很好,但是我不知道为什么它无法在textview中使用android M

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

这篇关于具有spanable的选择器在android M上不起作用,但在m以下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆