{"id":378,"date":"2014-11-18T20:07:31","date_gmt":"2014-11-19T04:07:31","guid":{"rendered":"http:\/\/appinventor.pevest.com\/?p=378"},"modified":"2014-11-18T20:07:31","modified_gmt":"2014-11-19T04:07:31","slug":"changing-the-color-of-a-button-or-other-components-in-app-inventor","status":"publish","type":"post","link":"https:\/\/coldstreams.com\/appinventor\/2014\/11\/18\/changing-the-color-of-a-button-or-other-components-in-app-inventor\/","title":{"rendered":"Changing the color of a button (or other components) in App Inventor"},"content":{"rendered":"<p>This tutorial covers the simple changing of the color of a button, <em>while the app is running<\/em>. You may also set a component&#8217;s color by changing the color properties on the Properties list in the Designer.<\/p>\n<p>A second tutorial will show how to implement the continuously changing color demonstrated in the <a href=\"https:\/\/www.youtube.com\/watch?v=xGlSakV49LI\">video example<\/a>. That will be posted next!<\/p>\n<p><strong>The Designer View<\/strong><\/p>\n<p>To demonstrate the &#8220;simple&#8221; version, create an app with this user interface:<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2014\/11\/ButtonChangeColor-Designer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-376\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2014\/11\/ButtonChangeColor-Designer.png\" alt=\"ButtonChangeColor-Designer\" width=\"304\" height=\"171\" \/><\/a><\/p>\n<p>That&#8217;s simple!<\/p>\n<p>Each time the button is pressed, the color of the button will change.<\/p>\n<p><strong>Blocks Code<\/strong><\/p>\n<p><!--more--><\/p>\n<p>To implement this feature, we set up a variable named <em>SelectedColor<\/em>. Each time the button is pressed, the value of <em>SelectedColor<\/em> is incremented by one.<\/p>\n<p>Then, our blocks code uses a sequence of <em>if-then-else<\/em> statements to check the value of <em>SelectedColor<\/em>, and change the button color. As you can see, below, if <em>SelectedColor<\/em> is 1, then the button color is set to red, and if 2, the color is set to yellow, and so on. The color values are selected from the <em>Colors<\/em> blocks in the Blocks editor.<\/p>\n<p><a href=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2014\/11\/ButtonChangeColor1-blocks.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-377\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2014\/11\/ButtonChangeColor1-blocks-1024x742.png\" alt=\"ButtonChangeColor1-blocks\" width=\"437\" height=\"317\" \/><\/a><\/p>\n<p>Many components have a <em>BackgroundColor<\/em> property and they too can have their colors change, programmatically, with code blocks similar to those used above.<\/p>\n<p><strong>Key Feature Shown<\/strong><\/p>\n<ul>\n<li>Color swatches!<\/li>\n<\/ul>\n<p><strong>Downloads<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/appinventor.pevest.com\/source\/tutorials\/ButtonChangeColor.aia\">Source code App Inventor \u201c.aia\u201d source file<\/a>\u00a0(App Inventor source code files have the filename extension .aia)<\/li>\n<li>Download the source code to your computer. Then, in App Inventor, go to the Projects menu and select \u201cImport project (.aia) from my computer\u2026\u201d<\/li>\n<\/ul>\n<p><strong>Please Share on Social Media<\/strong><\/p>\n<p>Please click on the buttons below this post to share with your friends on Facebook or other social media.<\/p>\n<p>If you are not already following this blog, click on the following links to like on Facebook, add to your Google+ circles or follow on Twitter or in your RSS news reader. Thank you for visiting!<\/p>\n<p><a href=\"https:\/\/www.facebook.com\/appinventor2\"><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/appinventor.pevest.com\/wp-content\/uploads\/2014\/10\/facebook-like.png\" alt=\"\" width=\"150\" \/><\/a><a href=\"https:\/\/plus.google.com\/107302082825289724871\/posts\"><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/coldstreams.com\/images\/plus-badge.png\" alt=\"\" width=\"48\" \/><\/a><a href=\"http:\/\/twitter.com\/appinventorplus\"><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/coldstreams.com\/images\/twitter-follow.png\" alt=\"\" width=\"100\" \/><\/a><a href=\"http:\/\/appinventor.pevest.com\/?feed=rss2\"><img decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/coldstreams.com\/images\/rss.png\" alt=\"\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial covers the simple changing of the color of a button, while the app is running. You may also set a component&#8217;s color by changing the color properties on the Properties list in the Designer. A second tutorial will show how to implement the continuously changing color demonstrated in the video example. That will &hellip; <a href=\"https:\/\/coldstreams.com\/appinventor\/2014\/11\/18\/changing-the-color-of-a-button-or-other-components-in-app-inventor\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Changing the color of a button (or other components) in App Inventor<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10],"tags":[],"class_list":["post-378","post","type-post","status-publish","format-standard","hentry","category-components","category-programming-method"],"_links":{"self":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/comments?post=378"}],"version-history":[{"count":0,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/posts\/378\/revisions"}],"wp:attachment":[{"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/media?parent=378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/categories?post=378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coldstreams.com\/appinventor\/wp-json\/wp\/v2\/tags?post=378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}