Tuesday, June 26, 2012

Android how to change the background, there are two ways, one is to use the background, one is to use picture 
Android itself is the default color is black, if we want to change the background color,

First res-> values ​​under the new xml file called color.xml
Join the following code
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="darkgray">#808080</drawable> <drawable name="white">#FFFFFF</drawable> <drawable name="blue">#0000FF</drawable> </resources> 


Then join in the main.xml (or your contentView xml file) which


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/white" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout> 

Then main.xml set your contentView replaced with white background
 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } 



Figure
So it seems a thing when the same XDD

White seems invisible XDDD




Next is the picture you want into the background
First, choose the one you want to get a picture,
Assumption is that this bgbypic.png

Create a folder called drawable in the res which

The future, if there are drawing, you are thrown into this folder

Then change just main.xml can change color, just the name replaced by Image Name.


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bgbypic" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > </LinearLayout> 


Then you can see the following screen




If you want to use code to control the background of it?

In the main.xml of change it, will LinearLayout more plus an id attribute


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bgbypic" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/myLinearLayout" > 


Then call. Java files inside it

 public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout linearlayout = (LinearLayout) findViewById(R.id.myLinearLayout); Resources res = this.getResources(); Drawable drawable = res.getDrawable(R.drawable.blue); linearlayout.setBackgroundDrawable(drawable); } 

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © .Hacking Cracking Tricks And Tutorials, Paid Scripts, Latest Exploits, 0Day Vulnerability, - Skyblue - Powered by Blogger - Designed by Johanes Djogan -