How to set text and text color of buttons

I create this guide on the demand of @SRIKAR_B.S.S

I this guide we learn how to set text and color of Button

As I told you in my first guide that to create any extension first of all we need import so in this extension we set text and text color of button so, first of we need import of button. You can get import of button from my first guide

Import of button
import android.widget.Button;

Code for set text and color of button

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.HVArrangement;
import android.widget.FrameLayout;
import android.widget.Button;
import android.view.View;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;

    private Activity activity;
    private Context context;
    private Button button;

@SimpleFunction(description = "1")
public void Create(HVArrangement arrangement) {
button = new Button(context);
View view = arrangement.getView();
FrameLayout frameLayout = (FrameLayout) view;
frameLayout.addView(button, new FrameLayout.LayoutParams(-1, -1));
}

@SimpleProperty(description = "2")
public void Text(String text) {
button.setText(text);
}

@SimpleProperty(description = "3")
public Object Text() {
Object text = button.getText();
return text;
}

@SimpleProperty(description = "4")
public void TextColor(String color) {
button.setTextColor(Color.parseColor(color));
}

How was this guide
  • Usefull
  • Not Usefull

0 voters

If you like this guide then click the like button :+1:

5 Likes

Very Nice Guide @Faraz_Firoz, Thank You So Much for creating a guide on this topic.
:star_struck: :slight_smile: :hugs:

1 Like

Tha k you @SRIKAR_B.S.S

Just a doubt, Wy need to set color, text… from aix if already possible in component?, Better make aix for a feature not available in components

Nor u explained wat every line of code does so, how can we firstly call it a guide

Error:

Started Compiling Project MyColor
Buildfile: /compiler/android/build.xml

javac:
[mkdir] Created dir: /compiler/android/build/nYbSV/classes
[javac] Compiling 1 source file to /compiler/android/build/nYbSV/classes
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /compiler/android/src/nYbSV/my/color/SRIKAR/FunmoraDev/MyColor.java:52: error: ')' expected
[javac] frameLayout.addView(button, new FrameLayout.LayoutParams(-1, -1);
[javac] ^
[javac] 1 error
[javac] 1 warning

I create this guide on the demand of @SRIKAR_B.S.S

can you solve my error?

Show me your code or dm me

Errors in Code I corrected them. :slight_smile:

Tell How to use this extension I am not getting how to use it. Also Show Blocks.

Thank you for edit

When screen1 initialize
Call Button1 Create arrangement = give a arrangement in which you want to create button
Set Button1 Text = your text
Set Button1 TextColor = your color
1 Like