Tutorial by Examples

You can archive different Textsizes inside a Textview with a Span TextView textView = (TextView) findViewById(R.id.textView); Spannable span = new SpannableString(textView.getText()); span.setSpan(new RelativeSizeSpan(0.8f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(span)...
public class CustomTextView extends TextView { private float strokeWidth; private Integer strokeColor; private Paint.Join strokeJoin; private float strokeMiter; public CustomTextView(Context context) { super(context); init(null); } public ...
A spannable TextView can be used in Android to highlight a particular portion of text with a different color, style, size, and/or click event in a single TextView widget. Consider that you have defined a TextView as follows: TextView textview=findViewById(R.id.textview); Then you can apply diff...
Android allows programmers to place images at all four corners of a TextView. For example, if you are creating a field with a TextView and at same time you want to show that the field is editable, then developers will usually place an edit icon near that field. Android provides us an interesting opt...
Strikethrough the entire text String sampleText = "This is a test strike"; textView.setPaintFlags(tv.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG); textView.setText(sampleText); Output: This is a test strike Strikethrough only parts of the text String sampleText = "This is a...
MainActivity.java: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } } activity_main.xml: <?xml version="1...
In order to make a RelativeSizeSpan align to the top, a custom class can be derived from the class SuperscriptSpan. In the following example, the derived class is named TopAlignSuperscriptSpan: activity_main.xml: <TextView android:id="@+id/txtView" android:layout_width=&quot...
activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation=...
Colored text can be created by passing the text and a font color name to the following function: private String getColoredSpanned(String text, String color) { String input = "<font color=" + color + ">" + text + "</font>"; return input; } The ...

Page 1 of 1