Changing text size and color of spinner in Sketchware

To change the text size and color of spinner dropdown list, follow the instructions given below.

1. In VIEW area of your Sketchware Android project, insert a Spinner spinner1.

2. In LOGIC area, add a new String list list1.

3. In onCreate event add items to the list.
4. After adding items to the String list, insert an add source directly block and put following code in it:

spinner1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, list1) {

@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView1 = (TextView) super.getView(position, convertView, parent);
textView1.setTextColor(Color.RED);
textView1.setTextSize(24);
return textView1; }

@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView textView1 = (TextView) super.getDropDownView(position, convertView, parent); textView1.setTextColor(Color.RED);
textView1.setTextSize(24);
return textView1; }
});

5. Add the block spinner1 refreshData.

6. Save and run the project.

Note that in the code above:
- spinner1 is the id of spinner,
- list1 is the String list,
- getView(int position, View convertView, ViewGroup parent) is the view of spinner in inactive(when dropdown list is not visible) state,

- getDropDownView(int position, View convertView, ViewGroup parent) is the view of spinner in when dropdown list is visible,

- textView1 is the TextView in spinner array and all operations valid for a TextView can be performed on it.

In the code above android.R.id.text1 is the TextView in layout android.R.layout.simple_list_item_1.


Comments

  1. Replies
    1. To change font, add the .ttf font using font manager, and then in the code above add this:

      textView1.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/aire.ttf"), 0);
      textView1.setBackgroundColor(Color.YELLOW);

      Here aire.ttf is the font added using font manager.

      Delete
    2. How to set background color to spinner as well?

      Delete
    3. How to do transparent background in spinner?

      Delete
  2. Super job. You are the best! How can I edit spaces between items of spinner?

    ReplyDelete
    Replies
    1. You add following code to code above:

      textView1.setHeight(300);

      And vary the height

      Delete
  3. How can I changed background colour of spinner

    ReplyDelete
  4. Please help ( I was created app before add items it's work but after add items and latest feature adding don't working

    ReplyDelete
  5. How to get child of child value from firebase in sketchware to appear on textview ?

    ReplyDelete
  6. example:

    Zone:
    Zone1:
    "Zone_1A" : "1A"
    "Zone_1B" : "1B"
    "Zone_1C" : "1C"
    Zone2:
    "Zone_2A" : "2A"
    "Zone_2B" : "2B"
    "Zone_2C" : "2C"
    Zone3:
    "Zone_3A" : "3A"
    "Zone_3B" : "3B"
    "Zone_3C" : "3C"

    How to get value of "Zone_1B" : "1B" in Sketchware to textview

    ReplyDelete
  7. Make reference to Firebase data location Zone.
    In onChildAdded,
    If childKey equals Zone1,
    textview1 setText( Map:childValue getkey Zone_1B)

    Check this video: https://youtu.be/x0hXyDTBPUw

    ReplyDelete
  8. Can we add value from map to list string to be use on spinner?

    ReplyDelete
  9. How to make spinner that get list from a STRING ARRAY?
    Could we do that in sketchware?

    ReplyDelete
  10. How can I set multiple spinner ?

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Creating a Drawing View in Sketchware

Enable Fullscreen for Youtube videos in WebView

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware