安卓页面点击跳转intent
来源:互联网 发布:ubuntu win10启动项 编辑:程序博客网 时间:2024/05/01 16:21
转载请标明出处:http://blog.csdn.net/wu_wxc/article/details/48195163
本文出自【吴孝城的CSDN博客】
安卓各个activity之间跳换用intent意图来实现,
需要编辑的文件如下
先写两个布局文件
activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="#ffffff" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="页面一" android:textSize="20sp"/> <Button android:id="@+id/bt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="跳到页面二" android:textSize="20sp"/></LinearLayout>
page2.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:background="#aaaaaa"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="页面二" android:textSize="20sp"/></LinearLayout>
然后在Java程序里使用意图跳转页面就行
MainActivity.java
package cn.wuxiaocheng.intent;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.widget.Button;public class MainActivity extends Activity { private Button bt1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { //通过findviewbyID获得按钮 bt1 = (Button) findViewById(R.id.bt1); //设置按钮点击事件 bt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, Page2.class); //启动意图 startActivity(intent); } }); }}第二个activity
Page2.java
package cn.wuxiaocheng.intent;import android.app.Activity;import android.os.Bundle;/** * Created by Administrator on 2015/9/3. */public class Page2 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.page2); }}最后别忘了,activity要在AndroidManifest.xml中注册
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.wuxiaocheng.intent" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Page2"> </activity> </application></manifest>
第十九二十行即为注册activity
运行效果如下
1 0
- 安卓页面点击跳转intent
- 安卓页面跳转-Intent
- 安卓:Intent的各种跳转系统页面
- 安卓页面跳转
- 安卓页面跳转
- 跳转,Intent跳转页面
- 安卓学习之路12之Intent实现页面跳转
- 安卓intent隐式跳转
- 安卓显示页面跳转
- 安卓开发页面跳转
- 安卓页面跳转 初级
- 安卓控件使用系列3:TextView点击连接跳转页面
- Intent实现页面跳转
- Intent实现页面跳转
- Intent页面跳转
- Intent实现页面跳转
- Intent实现页面跳转
- Android intent页面跳转
- 九度OJ-题目1003:A+B
- HDU5003-Osu!-AsiaRegionalAnshanOnline2014
- 修改view的x,y,width,height值的方法
- Unable to locate the model you have specified
- 从沙盒中取出被保存的图片
- 安卓页面点击跳转intent
- 详谈侧滑页面ViewPager的使用
- Android五分钟让你集成底部菜单栏(fragment或者fragment+viewpager)
- Android基础之intent-filter、action、category标签使用
- hdoj 3879 Base Station 【最小割 之 最大权闭合图】
- Android UI设计——ViewPage中自定义标题栏(四)
- shell脚本检测主机是否存活
- Sandbox Evasion with COM by Malware in-the-Wild
- 用序列之王splay解决线段树经典问题