【IT168 技术】如果要转换的页面不只是背景,颜色或文字内容的不同,而是Activity 的置换,那,那就不是单单改变Layout 就能完成的,尤其是需要传递的变量不像网页可以通过Cookie 或Session ,在程序里要移交主动权到另外一个Activity ,光靠先前技巧是办不到的.
而下面我们要讲的Intent 对象就是为解决这问题而生的,Intent 就如同其英文字义,是"想要"或"意图",之意,在主Activity 当中,告诉程序自己是什么,并想要前往哪里,这就是Intent 对象所处理的事了,本例子和前一个例子我们将实现同一个效果.
首先是布局main.xml 及mylayout.xml
main.xml:
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
< TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="欢迎来到魏祝林的博客"
/>
< Button
android:id="@+id/bt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击进入Layout2"
/>
< /LinearLayout>
mylayout.xml
< ?xml version="1.0" encoding="utf-8"?>
< LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
>
< TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome to Mr Wei's blog"
/>
< Button
android:id="@+id/bt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"