部分可点击的文本视图和不同的文本颜色-Android
我无法在xml中进行对齐。 我这样做 但是 我想这么做 我的xml代码是部分可点击的文本视图和不同的文本颜色-Android,android,xml,Android,Xml,我无法在xml中进行对齐。 我这样做 但是 我想这么做 我的xml代码是 <RelativeLayout android:layout_width="match_parent" android:layout_height="40dp" android:orientation="horizontal" android:layout_marginTop="25dp" an
<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个文本视图。其中一个是静态的,但第二个是动态的。当用户单击第二个文本视图时,片段将进入resister页面。您可以使用 文本视图布局
<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"
/>
尝试将第一个文本视图的高度设置为
match\u parent
,这会将您推向正确的方向。第二个文本视图的文本颜色为白色,因此在默认的白色背景上可能不可见这些注释不起作用。因为我想在同一文本视图中显示两种不同类型的文本。其中一个是正常的,另一个是可点击的@非常感谢,它工作得非常好。但是我做了一点修改来对齐文本。我在java代码的和处添加了;textView.setGravity(Gravity.CENTER);
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);