cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DavidWilson
Level: Powered On

How do you turn a button into a different colour when its pressed?

Hi,

 

I've added a button, what I want it to do is simply toggle between true and false and have it change colour to indicate that when pressed.

 

How do you do that?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: How do you turn a button into a different colour when its pressed?

Hi @JC75

 

Yup, looks like my understanding for English still needs more improvement.

(Maybe I always used to translate in my mind into Chinese when reading).

 

The best and most useful syntax used in PowerApps;

- UpdateContext

- x = x+1 (widely used in any programming languages for Looping purposes

- Switch (If is another alternative, but longer codes)

 

Here it is the final sample and hope this time I have understood your messages.

 

Screenshot (412).pngLoop, with unlimited Click; change as you wish!

 

Have a nice day.

Good nite.

hpkeong
18 REPLIES 18
Super User
Super User

Re: How do you turn a button into a different colour when its pressed?

Hi

 

Each button has many variable for you to control:

- PressedFill

- PressedColor

You can make changes over the color as you wish.

 

TQ

hpkeong
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: How do you turn a button into a different colour when its pressed?

If you want to change the color of the button while it's pressed, you can change the PressedColor (for the font color) and PressedFill (for the background color) of the button.

 

If you want to use the button as a toggle so that anytime it is pressed it will change the color of either the button itself or another control, you can use a context variable that is toggled in the OnSelect handler of the button. For example, if you want to use the button to toggle the color of itself and another control (say, a text box), you would use those formulas:

Button1.OnSelect: UpdateContext({ toggleValue: !toggleValue })
Button1.Color: If(toggleValue, Color.White, Color.Yellow)
Button1.Fill: If(toggleValue, Color.Blue, Color.Green)
TextBox1.Color: If(toggleValue, Color.Black, Color.White)
TextBox1.Fill: If(toggleValue, Color.White, Color.Black)
Highlighted
MarkieRMT
Level: Powered On

Re: How do you turn a button into a different colour when its pressed?

You can find the options mentioned by the other users by:

  • selecting the button
  • going to 'View'
  • click on 'Advanced'
  • in the advanced-section, click on the small arrow at the bottom of the section
DavidWilson
Level: Powered On

Re: How do you turn a button into a different colour when its pressed?

2016-05-15.png

 

It came up with an error, I copy and pasted it into the Action On Select part.

Thanks for you help everyone with this

Super User
Super User

Re: How do you turn a button into a different colour when its pressed?

Hi

 

You might have misunderstood Carlos.

 

1. Select the Button (which you wish to click), you can see OnSelect (Left Hand Side pane), and fill-in

UpdateContext({togglevalue: !togglevalue}) next to the box of fx.b

2. On the Left Pane again, look for Color & Fill and fill-in as:

Color (of the font inside the Button)...box next to fx: If(togglevalue, Color.White, Color. Yello})...or any color you wish

Fill... (fill of the Button)...box next to fx: If(togglevalue, Color.Green, Color.Red).....or any color you wish

TextBox1 (Color, Color, Border,...). as above

and any other.

 

You can change almost everything as long the you had accomplished No. 1: UpdateContext({togglevalue: !togglevalue}).

 

Note:

1. togglevalue is a Context Variable, you assign to the Button to toggle true and false when you click.

2. ! means reverse to the first value. If true, then false, if false, then true, and vice versa.

3. This Context Variable only works in the SAME SCREEN.

3. If(togglervalue,....) here togglevalue measn true

 

Hope this can clarify the whole scenario from Carlos.

 

hpkeong
DavidWilson
Level: Powered On

Re: How do you turn a button into a different colour when its pressed?

Bugger, I realy don't know what I'm doing here. I think I made a mess of it :0(

Super User
Super User

Re: How do you turn a button into a different colour when its pressed?

Hi

 

I did more mistake than you and misunderstood of what they said initially.

If you are catching up faster than be before.

Keep it up....Will always share to learn together.

Have a beautiful Sunday.

(Listen to Bonnie M)

hpkeong
JC75
Level: Powered On

Re: How do you turn a button into a different colour when its pressed?

Ok how woud you expand this to cycle through say 3 colours? I have a round shape, that each time the user selects it, i want it to cycle through Green, Orange, Red.

 

 

Super User
Super User

Re: How do you turn a button into a different colour when its pressed?

Hi @JC75

 

You have to use:

- Timer

- Set the Circle.Fill = 

            If(Timer1_1.Value <= 1000, Color.Green, Timer1_1.Value > 1000 && Timer1_1.Value <= 2000, Color.Orange, Color.Red)

 

Then, set your own Duration, Repeat, Autostart, ....

Example: Circle.OnSelect = UpdateContext({clickme1: !clickme1})

where clickme1 is the variable for Timer1_1

- Timer1_1.Start = clickme1.

 

Anyway, it is up to you to design.

 

Screenshot (410).pngClick on circle, and start

 

Hope this helps.

TQ

hpkeong

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 231 members 4,401 guests
Please welcome our newest community members: