Android(安卓)Studio学习路程(6)
16lz
2021-01-25
今天学习了如何进行界面之间的跳转。
用Intent进行页面跳转:
Intent是一个将要执行的动作的抽象的描述,由Intent来协助完成Android各个组件之间的通讯。下面是一些代码。
1 <?xml version="1.0" encoding="utf-8"?> 23 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:paddingBottom="@dimen/activity_vertical_margin" 7 android:paddingLeft="@dimen/activity_horizontal_margin" 8 android:paddingRight="@dimen/activity_horizontal_margin" 9 android:paddingTop="@dimen/activity_vertical_margin"10 android:orientation="vertical"11 tools:context="com.example.hp.app2.MainActivity">12 13 <Button14 android:id="@+id/btn1"15 android:text="按钮1"16 android:layout_width="match_parent"17 android:layout_height="wrap_content" />18 19 <Button20 android:id="@+id/btn2"21 android:text="按钮2"22 android:layout_width="match_parent"23 android:layout_height="wrap_content" />24 25 26
package com.example.hp.app2;import android.os.Bundle;import android.support.v7.app.ActionBarActivity;/** * Created by hp on 2020/2/11. */public class FirstActivity extends ActionBarActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); }}
<?xml version="1.0" encoding="utf-8"?>android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:textSize="25dp" android:textColor="@android:color/holo_red_light" android:text="这是第一个界面" android:layout_width="wrap_content" android:layout_height="wrap_content" />
1 package com.example.hp.app2; 2 3 import android.content.Intent; 4 import android.os.Bundle; 5 import android.support.v7.app.ActionBarActivity; 6 import android.view.View; 7 8 public class MainActivity extends ActionBarActivity implements View.OnClickListener { 9 10 @Override11 protected void onCreate(Bundle savedInstanceState) {12 super.onCreate(savedInstanceState);13 setContentView(R.layout.activity_main);14 initUI();15 }16 17 private void initUI() {18 findViewById(R.id.btn1).setOnClickListener( this);19 findViewById(R.id.btn2).setOnClickListener( this);20 }21 22 23 @Override24 public void onClick(View view) {25 switch (view.getId()){26 case R.id.btn1:27 //跳转到第一个界面28 //跳转界面用到了intent的方法29 Intent intent = new Intent();30 intent.setClass(getApplicationContext(),FirstActivity.class);31 break;32 case R.id.btn2:33 //第二个界面34 break;35 36 }37 }38 }
更多相关文章
- UI布局之selector layer-list
- Android(安卓)自定义view仿微信相机单击拍照长按录视频按钮
- 【Android(安卓)界面效果49】RecyclerView高度随Item自适应
- Android(安卓)菜单BoomMenu(悬浮按钮弹出菜单)
- 关于Android界面编程与视图(View)组件
- Eclipse集成Android(安卓)NDK开发环境
- Android自定义Dialog弹框效果
- Android(安卓)ListView pull up to refresh 改造
- Android——四大组件、六大布局、五大存储