-3
<TextView 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Don't have an account? Sign up"
android:textAlignment="center"
android:textSize="19sp"/>

How should make the word "sign up" clickable and how that style it in italic without using a new textView component. I'm using linear layout.

1 Answers1

0

To make Sign Up Italic create a String resource like this.

<string name="register"><u><b>Don't have an account? <i>Sign Up</i></b></u></string>

You can also use HTML block and set that HTML to text view.

SpannableString is the key to acheive that And to make signup clickable use this code.

SpannableString ss = new SpannableString("Don't have an account? Sign up");
ClickableSpan clickableSpan = new ClickableSpan() {
    @Override
    public void onClick(View textView) {
        startActivity(new Intent(MyActivity.this, NextActivity.class));
    }
    @Override
    public void updateDrawState(TextPaint ds) {
        super.updateDrawState(ds);
        ds.setUnderlineText(false);
    }
};
ss.setSpan(clickableSpan, 24, 30, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

TextView textView = (TextView) findViewById(R.id.register);
textView.setText(ss);
Dipendra Sharma
  • 2,404
  • 2
  • 18
  • 35