我正在尝试进行"Accept terms and conditions"开关。我能够将链接添加到交换机中,但是问题是该链接也位于交换机按钮上,因此每次我按下按钮以接受将其带到网页的条款和条件时,都可以。

我希望只有被选为链接的文本才是链接。

这是我现在拥有的代码:

在strings.xml上:

<string name="terms">Accept<a href="http://www.google.es">terms & conditions</a>.</string>


在register.xml上:

<Switch
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/terms"
     android:id="@+id/registerSwitch"/>


在Register.class上:

Switch terms = (Switch) findViewById(R.id.registerSwitch);
terms.setMovementMethod(LinkMovementMethod.getInstance());


如何使仅文本"terms & conditions"是链接而不是切换按钮?

最佳答案

为什么不以TextView和setOnClickListener的形式分别在TextView上显示文本以打开链接。一些像这样的东西:

         <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <Switch
                android:id="@+id/your_switch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/terms_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Accept terms &amp; conditions" />

        </LinearLayout>


活动中

TextView termsText = (TextView)findViewById(R.id.terms_text);
    termsText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.yoururl.com"));
            startActivity(browserIntent);
        }
    });

关于android - 如何添加到“开关”小部件的文本的链接?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38766890/

10-12 00:38
查看更多