cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

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

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.

 

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

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
Highlighted
Power Apps
Power Apps

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

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
Highlighted
Helper II
Helper II

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

Highlighted
Community Champion
Community Champion

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
Highlighted
Helper II
Helper II

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(

Highlighted
Community Champion
Community Champion

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

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.

 

 

Highlighted
Community Champion
Community Champion

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.

 

Click on circle, and startClick on circle, and start

 

Hope this helps.

TQ

hpkeong

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,537)