Android Projects

Android Development Books

Thursday

Apply Colors to Android Controls and Layouts

Desgining concept in Android development that is"Apply colors to android controls like (Buttons,Textviews,etc..) and applying Background colors to Different Layouts"..So lets start



First,Create an xml file in your project and change the name as colors.xml

Next,Save this file in values folder which under the res folder like this res/values/colors.xml

Next,Decide which colors you would like to add.

Next,Open the colors.Xml file and add the following code

Here, We are appying only Background colors.
<resources>


     <color name="completeBackground">#303030</color>
     <color name="HeaderBackground">#000000</color>
            <color name="SideBackground">#FFFFFF</color> 
     <color name="ContentBackground">#F0F0F0</color>
</resources>
Note: Change the colors as per your requirment

Now save this file and open another xml file to apply these colors to layouts

Open the Layout1.xml file and add the following code

<linearlayout android:background="@color/completeBackground" android:gravity="left" android:layout_height="200dip" android:layout_width="wrap_content" android:orientation="horizontal" android:paddingleft="50dip" android:paddingtop="55dip">


<textview android:layout_height="40dip" android:layout_width="wrap_content" android:paddingleft="10dip" android:paddingtop="10dip" android:text="Header" android:textsize="16sp">


</textview></linearlayout>

//// Another Sub parent Layout’s

<linearlayout android:background="@color/completeBackground" android:id="@+id/Sub_Parent_LinearLayout" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="horizontal">

// these are the Child Layout’s

<linearlayout android:background="@color/SideBackground" android:gravity="left" android:layout_height="wrap_content" android:layout_width="300dip" android:orientation="horizontal" android:paddingleft="50dip" android:paddingtop="55dip">


<textview android:layout_height="40dip" android:layout_width="wrap_content" android:paddingleft="10dip" android:paddingtop="10dip" android:text="LeftSidebar" android:textsize="16sp">


</textview></linearlayout>


<linearlayout android:background="@color/ContentBackground" android:gravity="left" android:layout_height="wrap_content" android:layout_width="600dip" android:orientation="horizontal" android:paddingleft="50dip" android:paddingtop="55dip">


  <textview android:layout_height="40dip" android:layout_width="wrap_content" android:paddingleft="10dip" android:paddingtop="10dip" android:text=" Content " android:textsize="16sp">


  </textview>


</linearlayout>


  </linearlayout>

 

Note : you need to add this line (android:background="@color/completeBackground")

Next,Lets start appyling colors to Android controls

Again open the colors.xml file and add the following lines in the file

<resources>


     <color name="completeBackground">#303030</color>
     <color name="HeaderBackground">#000000</color>
            <color name="SideBackground">#FFFFFF</color> 
     <color name="ContentBackground">#F0F0F0</color>


            <color name="ButtonBackground">#000000</color>
            <color name="TextViewBackground">#000000</color>
           
</resources>


Now save the file..and apply colors to Controls
 
<button android:background="@drawable/ButtonBackground" android:id="@+id/mybutton" android:text="colorbutton">

<textview android:background="@drawable/TextViewBackground" android:id="@+id/myTextView" android:text="colorText">

</textview></button>

Sources: http://www.developerscode.com/


Share this post
  • Share to Facebook
  • Share to Twitter
  • Share to Google+
  • Share to Stumble Upon
  • Share to Evernote
  • Share to Blogger
  • Share to Email
  • Share to Yahoo Messenger
  • More...

0 comments

Thanks for your comment

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

Related Posts Plugin for WordPress, Blogger...
© Google Android Lovers
Designed by BlogThietKe Cooperated with Duy Pham
Released under Creative Commons 3.0 CC BY-NC 3.0