Posts

Showing posts with the label SuperscriptSpan in Sketchware

SubscriptSpan and Superscript span example in Sketchware

Image
SubscriptSpan example The span that moves the position of the text baseline lower. Note: Since the span affects the position of the text, if the text is on the last line of a TextView, it may appear cut. Constructor: SubscriptSpan() Creates a SubscriptSpan. This example shows use of SubscriptSpan in Sketchware. 1. In  main.xml  add a TextView  textview1 . 2. In  MainActivity.java , create a new String  mystring . 3. In  onCreate  of  MainActivity.java : a. Set the text of  mystring  to: H2O = Water b. Use an add source directly block to put following codes: // Convert this String to a Spannable String  ss . SpannableString ss = new SpannableString(mystring); // Add SubscriptSpan to 2 of H2O in above text. ss.setSpan(new android.text.style.SubscriptSpan(), 1, 2, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Display the Spannable String in TextView. textview1.setText(ss); 4. Save and run the project. It will s...