Set gradient color background for a view

Wednesday, 14 August 2013 by

A Drawable with a color gradient for views(e.g-button) can be set defining in an XML file with the <shape> element. Color gradient for a view can be set both from xml or programmatically: Code for layout: Code for res/drawable/background_inner.xml: Code for setting gradient color background programmatically: Code for layout: Code for activity:      

This example demonstrate how to define rounded-rect shape for View as well as set layoutborder.The rounded rectangle can be drawn to a Canvas with its own draw() method, but more graphical control is available if you instead pass the RoundRectShape to a ShapeDrawable.A ShapeDrawable takes a Shape object and manages its presence on the screen.

Set Button background

Monday, 05 August 2013 by

A button consists of text or an icon (or both text and an icon) that communicates what action occurs when the user touches it.To customize individual buttons with a different background, specify the android:background attribute with a drawable or color resource. This code is for setting background image of a button and set background color