SubscriptSpan and Superscript span example in Sketchware

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 show result as in image below.



SuperscriptSpan example

The span that moves the position of the text baseline higher.

Note: Since the span affects the position of the text, if the text is on the first line of a TextView, it may appear cut. This can be avoided by decreasing the text size with an AbsoluteSizeSpan.

Constructor:
SuperscriptSpan()
Creates a SuperscriptSpan.

This example shows use of SuperscriptSpan 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:
We three are the 1st, 2nd and 3rd here.

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 SuperscriptSpan to 'st' of 1st, 'nd' of 2nd and 'rd' of 3rd in above text.
ss.setSpan(new android.text.style.SuperscriptSpan(), 18, 20, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new android.text.style.SuperscriptSpan(), 23, 25, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new android.text.style.SuperscriptSpan(), 31, 33, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

// Display the Spannable String in TextView.
textview1.setText(ss);

4. Save and run the project. It will show result as in image below.

Comments

  1. How to read and download PDF file from webpage on Sketchware. Pls help me.

    ReplyDelete
  2. Okay but let me rephrase the question ........... I made a (MoreBlock) called (add) which has 3 variables, the first is called (pos) and is (Number), the second is called (code) and it is (Boolean) and the third one is called (description) and it is (Boolean) ............ then I made a (MoreBlock) called (codes) which I added several blocks called ( add); in each one I put a value the pos I started from 0 and the rest increases one by one 0.1,2,3, ... in (code) they have texts and in (description) they have other texts and what I want to do is put buttons (Button) menu type, which when pressing the first call key 0 and key (code) of the block (codes) to get the text --GetText-- of (code) and with ( SetText) put it in an (EditText) but no matter how hard I try, I don't send you the project so that you understand it better https://1drv.ms/u/s!AjUQDCAtSdWgjRVFTM_FBBKGjRqP?e=KgHF6p

    ReplyDelete
    Replies
    1. I think you need a custom ListView. Create a Maplist. Add items (Map variables) to it. In each Map variable add key code and description with their values.

      Delete

Post a Comment

Popular posts from this blog

Create Music Player app in Sketchware

A Flash Light App in Sketchware

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity

In Sketchware: How to create a calculator for any simple formula?