Modify strings. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "layout1"> This is layout 1 </string> <string name = "layout2"> This is layout 2 </string> <string name =" app_name "> ex8_ui </string> </resources>
Create a new color. xml file and save the two color values in the Res/values directory)
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <color name = "black"> #000000 </color> <color name = "white"> # ffffffff </color> </resources>
Modify the main. xml layout and add a textview and a button
<? XML version = "1.0" encoding = "UTF-8"?> <Absolutelayoutandroid: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "@ color/Black" xmlns: Android = "http://schemas.android.com/apk/res/android"> <textviewandroid: id = "@ + ID/text1" Android: textsize = "24sp" Android: layout_width = "186px" Android: layout_height = "29px" Android: layout_x = "70px" Android: layout_y = "32px" Android: text = "@ string/layout1"> </textview> <buttonandroid: Id = "@ + ID/button1" Android: layout_width = "118px" Android: layout_height = "wrap_content" Android: layout_x = "100px" Android: layout_y = "82px" Android: TEXT = "go to layout2"> </button> </absolutelayout>
Create a new mylayout. xml layout file (put in the Res/layout directory) and add two views: textview and button.
<? XML version = "1.0" encoding = "UTF-8"?> <Absolutelayoutandroid: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Background = "@ color/White" xmlns: Android = "http://schemas.android.com/apk/res/android"> <textviewandroid: id = "@ + ID/text2" Android: textsize = "24sp" Android: layout_width = "186px" Android: layout_height = "29px" Android: layout_x = "70px" Android: layout_y = "32px" Android: textcolor = "@ color/Black" Android: text = "@ string/layout2"> </textview> <buttonandroid: id = "@ + ID/button2" Android: layout_width = "118px" Android: layout_height = "wrap_content" Android: layout_x = "100px" Android: layout_y = "82px" Android: TEXT = "go to layout1"> </button> </absolutelayout>
Compile mainactivity. Java
/** To change this template, choose tools | templates * and open the template in the editor. */package Org. me. setcontentviewapp; import android. app. activity; import android. OS. bundle; import android. view. view; import android. widget. button;/*** @ author liaokecheng