{"id":260,"date":"2014-04-07T20:26:00","date_gmt":"2014-04-07T18:26:00","guid":{"rendered":"http:\/\/www.albertopasca.it\/whiletrue\/?p=260"},"modified":"2018-05-25T13:41:21","modified_gmt":"2018-05-25T11:41:21","slug":"android-button-with-rounded-corners","status":"publish","type":"post","link":"http:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/","title":{"rendered":"[Android] \u2013 Button with rounded corners"},"content":{"rendered":"<p>Based on the last post, for iOS \u201c<a href=\"http:\/\/www.albertopasca.it\/whiletrue\/2014\/04\/objc-uibutton-rounded-corners\/\" target=\"_blank\" rel=\"noopener\">UIButton with rounded corners<\/a>\u201c, now the Android version.<\/p>\n<p>It\u2019s just a simple shape file (xml).<\/p>\n<p><!--more--><\/p>\n<p>In your\u00a0<strong>res<\/strong>\u00a0project folder, make a new folder called\u00a0<strong>xml<\/strong>\u00a0of type xml, and add a new shape file, for example\u00a0<strong>rounded_blue.xml<\/strong>.<\/p>\n<p>[code lang=&#8221;xml&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]<br \/>\n&lt;?xml\u00a0version=&quot;1.0&quot;\u00a0encoding=&quot;utf-8&quot;?&gt;<br \/>\n&lt;shape\u00a0xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;&gt;<br \/>\nandroid:shape=&quot;rectangle&quot;&gt;<br \/>\n&lt;gradient\u00a0android:startColor=&quot;#2D8CD6&quot;<br \/>\nandroid:endColor=&quot;#2D8CD6&quot;<br \/>\nandroid:angle=&quot;270&quot;&gt;&lt;\/gradient&gt;<\/p>\n<p>&lt;corners\u00a0android:bottomRightRadius=&quot;0dp&quot;<br \/>\nandroid:bottomLeftRadius=&quot;25dp&quot;<br \/>\nandroid:topLeftRadius=&quot;0dp&quot;<br \/>\nandroid:topRightRadius=&quot;25dp&quot;&gt;&lt;\/corners&gt;<br \/>\n&lt;\/shape&gt;[\/code]<\/p>\n<p>In this file you can specify\u00a0<strong>startColor<\/strong>\u00a0and\u00a0<strong>endColor<\/strong>, put different color if you want a gradient rounded button..<\/p>\n<p>In\u00a0<strong>corners<\/strong>\u00a0tag, you can define the dp for radius for each corner.<\/p>\n<p>Now, in your Layout file, add a button and\u00a0<strong>set as background the shape file<\/strong>!<br \/>\nLike this:<\/p>\n<p>[code lang=&#8221;xml&#8221; autolinks=&#8221;false&#8221; collapse=&#8221;false&#8221; firstline=&#8221;1&#8243; gutter=&#8221;true&#8221; htmlscript=&#8221;false&#8221; light=&#8221;false&#8221; padlinenumbers=&#8221;false&#8221; smarttabs=&#8221;true&#8221; tabsize=&#8221;4&#8243; toolbar=&#8221;false&#8221;]<br \/>\n&lt;button\u00a0android:background=&quot;@drawable\/rounded_blue&quot;<br \/>\nandroid:layout_width=&quot;match_parent&quot;<br \/>\nandroid:layout_height=&quot;match_parent&quot;<br \/>\nandroid:text=&quot;@string\/homeText&quot;<br \/>\nandroid:id=&quot;@+id\/buttonHome&quot;<br \/>\nandroid:textColor=&quot;#ffffff&quot;<br \/>\n[&#8230;]<br \/>\nandroid:lines=&quot;3&quot;&gt;&lt;\/button&gt;[\/code]<\/p>\n<p>Well done!<br \/>\nLeft image is the preview in Android Studio, on the rigth, in a real device!<\/p>\n<div id='gallery-1' class='gallery galleryid-260 gallery-columns-2 gallery-size-medium'><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"204\" height=\"300\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png?fit=204%2C300\" class=\"attachment-medium size-medium\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png?w=230 230w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png?resize=204%2C300 204w\" sizes=\"auto, (max-width: 204px) 100vw, 204px\" \/><\/a>\n\t\t\t<\/div><\/figure><figure class='gallery-item'>\n\t\t\t<div class='gallery-icon portrait'>\n\t\t\t\t<a href=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.21.35-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"202\" height=\"300\" src=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.21.35-1.png?fit=202%2C300\" class=\"attachment-medium size-medium\" alt=\"\" srcset=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.21.35-1.png?w=434 434w, https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.21.35-1.png?resize=202%2C300 202w\" sizes=\"auto, (max-width: 202px) 100vw, 202px\" \/><\/a>\n\t\t\t<\/div><\/figure>\n\t\t<\/div>\n\n<p>enjoy rounding!<\/p>\n<p>Here the iOS version:\u00a0<a href=\"http:\/\/www.albertopasca.it\/whiletrue\/2014\/04\/objc-uibutton-rounded-corners-2\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.albertopasca.it\/whiletrue\/2014\/04\/objc-uibutton-rounded-corners-2\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Based on the last post, for iOS \u201cUIButton with rounded corners\u201c, now the Android version. It\u2019s just a simple shape file (xml).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[141,122,116,121,129],"class_list":["post-260","post","type-post","status-publish","format-standard","hentry","category-generic","tag-android","tag-aproundedbutton","tag-java","tag-mobile","tag-uibutton"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>[Android] \u2013 Button with rounded corners - while (true) {\u00a0}<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Android] \u2013 Button with rounded corners - while (true) {\u00a0}\" \/>\n<meta property=\"og:description\" content=\"Based on the last post, for iOS \u201cUIButton with rounded corners\u201c, now the Android version. It\u2019s just a simple shape file (xml).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/\" \/>\n<meta property=\"og:site_name\" content=\"while (true) {\u00a0}\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-07T18:26:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-05-25T11:41:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png?fit=204%2C300&amp;ssl=1\" \/>\n<meta name=\"author\" content=\"Alberto Pasca\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lupasca\" \/>\n<meta name=\"twitter:site\" content=\"@lupasca\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alberto Pasca\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/\"},\"author\":{\"name\":\"Alberto Pasca\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"headline\":\"[Android] \u2013 Button with rounded corners\",\"datePublished\":\"2014-04-07T18:26:00+00:00\",\"dateModified\":\"2018-05-25T11:41:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/\"},\"wordCount\":311,\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"keywords\":[\"android\",\"APRoundedButton\",\"Java\",\"Mobile\",\"uibutton\"],\"articleSection\":[\"generic\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/\",\"name\":\"[Android] \u2013 Button with rounded corners - while (true) {\u00a0}\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\"},\"datePublished\":\"2014-04-07T18:26:00+00:00\",\"dateModified\":\"2018-05-25T11:41:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/android-button-with-rounded-corners\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Android] \u2013 Button with rounded corners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#website\",\"url\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/\",\"name\":\"while (true) {\u00a0}\",\"description\":\"notes from a developer, tutorials, how-to, ideas\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.albertopasca.it\\\/whiletrue\\\/#\\\/schema\\\/person\\\/d3cf0df774eb4aac797f246a795e9fac\",\"name\":\"Alberto Pasca\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\",\"caption\":\"Alberto Pasca\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g\"},\"description\":\"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.\",\"sameAs\":[\"https:\\\/\\\/www.albertopasca.it\",\"albertopasca\",\"https:\\\/\\\/x.com\\\/lupasca\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Android] \u2013 Button with rounded corners - while (true) {\u00a0}","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/","og_locale":"en_US","og_type":"article","og_title":"[Android] \u2013 Button with rounded corners - while (true) {\u00a0}","og_description":"Based on the last post, for iOS \u201cUIButton with rounded corners\u201c, now the Android version. It\u2019s just a simple shape file (xml).","og_url":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/","og_site_name":"while (true) {\u00a0}","article_published_time":"2014-04-07T18:26:00+00:00","article_modified_time":"2018-05-25T11:41:21+00:00","og_image":[{"url":"https:\/\/i0.wp.com\/www.albertopasca.it\/whiletrue\/wp-content\/uploads\/2014\/04\/Screenshot-2014-04-07-09.16.42-1.png?fit=204%2C300&amp;ssl=1","type":"","width":"","height":""}],"author":"Alberto Pasca","twitter_card":"summary_large_image","twitter_creator":"@lupasca","twitter_site":"@lupasca","twitter_misc":{"Written by":"Alberto Pasca","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/#article","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/"},"author":{"name":"Alberto Pasca","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"headline":"[Android] \u2013 Button with rounded corners","datePublished":"2014-04-07T18:26:00+00:00","dateModified":"2018-05-25T11:41:21+00:00","mainEntityOfPage":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/"},"wordCount":311,"publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"keywords":["android","APRoundedButton","Java","Mobile","uibutton"],"articleSection":["generic"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/","url":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/","name":"[Android] \u2013 Button with rounded corners - while (true) {\u00a0}","isPartOf":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website"},"datePublished":"2014-04-07T18:26:00+00:00","dateModified":"2018-05-25T11:41:21+00:00","breadcrumb":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.albertopasca.it\/whiletrue\/android-button-with-rounded-corners\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.albertopasca.it\/whiletrue\/"},{"@type":"ListItem","position":2,"name":"[Android] \u2013 Button with rounded corners"}]},{"@type":"WebSite","@id":"https:\/\/www.albertopasca.it\/whiletrue\/#website","url":"https:\/\/www.albertopasca.it\/whiletrue\/","name":"while (true) {\u00a0}","description":"notes from a developer, tutorials, how-to, ideas","publisher":{"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.albertopasca.it\/whiletrue\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.albertopasca.it\/whiletrue\/#\/schema\/person\/d3cf0df774eb4aac797f246a795e9fac","name":"Alberto Pasca","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g","caption":"Alberto Pasca"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/4d8fe43c412d0bb34a71c41f60dce53eff3afc027853cbfd20bee6ddc7e93f35?s=96&d=retro&r=g"},"description":"Software engineer @ Pirelli &amp; C. S.p.A. with a strong passion for mobile \uf8ff development, security, and connected things.","sameAs":["https:\/\/www.albertopasca.it","albertopasca","https:\/\/x.com\/lupasca"]}]}},"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/comments?post=260"}],"version-history":[{"count":4,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/260\/revisions"}],"predecessor-version":[{"id":764,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/posts\/260\/revisions\/764"}],"wp:attachment":[{"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/media?parent=260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/categories?post=260"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.albertopasca.it\/whiletrue\/wp-json\/wp\/v2\/tags?post=260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}