cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
hpkeong
Community Champion
Community Champion

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.

 

Loop, with unlimited Click; change as you wish!Loop, with unlimited Click; change as you wish!

 

Have a nice day.

Good nite.

hpkeong

View solution in original post

19 REPLIES 19
hpkeong
Community Champion
Community Champion

Hi

 

Each button has many variable for you to control:

- PressedFill

- PressedColor

You can make changes over the color as you wish.

 

TQ

hpkeong
CarlosFigueira
Power Apps
Power Apps

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)
MarkieRMT
Regular Visitor

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
Anonymous
Not applicable

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

hpkeong
Community Champion
Community Champion

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
Anonymous
Not applicable

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

hpkeong
Community Champion
Community Champion

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
Advocate IV
Advocate IV

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.

 

 

hpkeong
Community Champion
Community Champion

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.

 

Click on circle, and startClick on circle, and start

 

Hope this helps.

TQ

hpkeong

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,592)