我的xml代码是;
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginTop="25dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center">
<TextView
android:id="@+id/signup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#733E3A"
android:textSize="15dp"
android:text="@string/have_account"
fontPath="fonts/pfdindisplaypro-regular.ttf"
tools:ignore="MissingPrefix"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/txt_login_go_to_register"
android:onClick="loginOnClickListener"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/signup1"
android:textColor="@color/white"
android:layout_marginLeft="7dp"
android:textSize="15dp"
android:text="@string/txt_register_title"
fontPath="fonts/pfdindisplaypro-regular.ttf"
tools:ignore="MissingPrefix"
android:layout_gravity="center_horizontal" />
</RelativeLayout>
我使用了2个TextView。其中一个是静态的,但第二个是动态的。当用户单击第二个TextView时,该片段将转到resister页面。
答案 0 :(得分:2)
您可以使用Spannable
实现此目的TextView布局。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:clickable="true"
android:background="#BF7366" //Use your Background image or any other color
android:padding="5dp"
/>
在您的activity.java
中TextView textView =(TextView) findViewById(R.id.textView);
textView.setMovementMethod(LinkMovementMethod.getInstance());
Spannable word = new SpannableString("Don`t have account yet? ");
word.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.text_color)), 0, word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(word);
final Spannable wordTwo = new SpannableString("Sign up here and join our exciting team.");
ClickableSpan myClickableSpan = new ClickableSpan()
{
@Override
public void onClick(View widget) {
// There is the OnCLick. put your intent to Register class here
widget.invalidate();
}
@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(Color.WHITE);
ds.setUnderlineText(false);
}
};
wordTwo.setSpan(myClickableSpan,0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.append(wordTwo);