第五篇-以显式意图(Explicit Intent)跳往其它Activity
此项目基于第四篇。
Intent(意图)
Explicit Intent(显式意图):
- 清楚指明需要前往的Activity的名称
- 用于APP内部的连接
Inplicit Intent(隐式意图):
- 不明确知名需前往的Activity名称
- 只提出大概意图:
- 如开启一个网页(但不指明用哪个浏览器打开)
- 拨打一个电话(但不指明用哪个通讯工具执行)
- 一般用于呼叫APP内部以外的系统功能
app/res/layout下新建一个layout.xml文件,同样右击linearLayout,Convert view。。。变为ConstraintLayout。
拉一个TextView到预览界面,修改text为Screen #1,连接上左右三个方向,接着改变文字大小,右侧拉到最下方,点击View all attributes,将textsize设为80sp,点击textcolor后面...,选择颜色为colorAccent,点击ok。
在拉一个Button按钮到预览界面。设置其文字为Jump To Screen #2。连接左右,并将上方连接到TextView的下方。如果觉得按钮和文本距离太近了,可以改变距离,在右侧可以看到一个方块,上左右分别显示8,如果相让给文本和按钮距离变大,可以讲过按钮上方的距离由8变为32。并将layout_width变为match_constraint。
在app/java/com...就是之前放main.java的路径下新建一个java文件。new->activity->empty activity。注意过程中不要在Launcher Activity处打勾。将之前设计的页面layout3.xml切换到text模式全选复制,粘贴到layout4.xml下面。修改Screen #1->Screen #2,修改Jump To Screen #2->Jump To Screen #2。现在有两个外观档,layout3.xml,layout4,xml。将layout4.xml和新建的layout4Activity.java关掉,看layout3.xml。如果要让按下按钮Jump To Screen #2跳到Screen #2的页面,即layout4.xml页面,可以在layout3.xml中text文本模式,在Button标签里面添加android:onClick="JumpToScreen2",因此要在mian.java文件中添加一个JumpToScreen2函数。如果想要偷懒的话,就在那一行按住Alt+enter,会自动在.java文件里给你创建一个函数。在里面写入Intent i=new Intent(this,Layout4Activity.class);startActivity(i);此时已经完成了点击按钮会跳入第二个页面。
layout3.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Screen #1"
android:textColor="@color/colorAccent"
android:textSize="80sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> <Button
android:id="@+id/button8"
android:onClick="JumpToScreen2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="Jump To Screen #2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
layout4.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"> <TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:text="Screen #2"
android:textColor="@color/colorAccent"
android:textSize="80sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> <Button
android:id="@+id/button8"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:text="Jump To Screen #3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>
main.java:
package com.example.aimee.aimeetest1; import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.layout);
setContentView(R.layout.layout3);
} public void JumpToScreen2(View view) {
Intent i=new Intent(this,Layout4Activity.class);
startActivity(i);
}
}
layout4Activity.java:
package com.example.aimee.aimeetest1; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; public class Layout4Activity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout4);
}
}
第五篇-以显式意图(Explicit Intent)跳往其它Activity的更多相关文章
- 显式意图启动一个Activity
显式意图主要是通过指定包名和类名开启一个组件,主要用于安全性要求高的,且不想被其他应用开启,可以不配置应用过滤器. 1.创建意图对象 Intent intent = new Intent(); 2.指 ...
- 无废话Android之smartimageview使用、android多线程下载、显式意图激活另外一个activity,检查网络是否可用定位到网络的位置、隐式意图激活另外一个activity、隐式意图的配置,自定义隐式意图、在不同activity之间数据传递(5)
1.smartimageview使用 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
- [android] 隐式意图和显式意图的使用场景
激活系统的某些应用,并且往应用里面填一些数据,比如说短信应用 打开短信应用,查看logcat,找到ActivityManager, 看到Display.com.android.mms/.ui.Comp ...
- [Selenium]显式等待 Explicit wait & 隐式等待 Implicit wait
显式等待 Explicit wait 显示等待 , 就是明确的要等到某个元素出现或者某个元素满足某种条件,每隔一段时间检查一次,等不到,就一直等,如果在规定的时间内还没有找到,就跳出来检查间隔的时间和 ...
- Android中显式意图和隐式意图的区别
1.显式意图 可以直接通过名称开启指定的目标组件: 通过构造方法Intent(Context packageContext,class<?>cls)来实现. button_1 = (But ...
- Activity组件:(一)通过显式意图和隐式意图来实现Activity间的跳转
一.通过显式意图来实现Activity间的跳转 显式意图是指在创建Intent对象时就指定接受者组件 /** * 下面是通过显式意图进行跳转,即明确写出要跳转到SecondActivity.class ...
- Activity组件(二):通过显式意图和隐式意图来跳转至第三方应用
一.显式意图来跳转到第三方应用 /** * 这个方法会在点击按钮的时候执行 * @param view */ public void skip2Browser(View view){ Log.d(TA ...
- android 21 隐式意图启动系统预定义activity
Intent intent=new Intent(LoginActivity.this, MainActivity.class);//显示意图启动,显示从一个activity到另一个activity, ...
- 第六篇-以隐式意图(Implicit Intent)呼叫系统服务
一.新建一个layout5.xml,同样换为constriant模式. 二.拖动两个Button到预览界面,第一个按钮名字改为DISPLAY WEBPAGE,第二个按钮名字改为MAKE A CALL. ...
随机推荐
- LeetCode & Online Programming Learning Platform
leetcode LeetCode is the best platform to help you enhance your skills, expand your knowledge and pr ...
- 集合之LinkedList(含JDK1.8源码分析)
一.前言 LinkedList是基于链表实现的,所以先讲解一下什么是链表.链表原先是C/C++的概念,是一种线性的存储结构,意思是将要存储的数据存在一个存储单元里面,这个存储单元里面除了存放有待存储的 ...
- python functools.wraps functools.partial实例解析
一:python functools.wraps 实例 1. 未使用wraps的实例 #!/usr/bin/env python # coding:utf-8 def logged(func): de ...
- SQL Server与SQL Server Express的区别
SQL Server Express 2005(以下简称 SQLExpress) 是由微软公司开发的 SQL Server 2005(以下简称 SQL2005)的缩减版,这个版本是免费的,它继承了 S ...
- 规范化Normalization
一.批规范化 Batch Normalization 转自: http://blog.csdn.net/hjimce/article/details/50866313 https://zhuan ...
- codeforces630C
Lucky Numbers CodeForces - 630C 小希称只含7和8的数是幸运数,那么不超过n位的幸运数有多少个? Input 一个整数 n (1 ≤ n ≤ 55) Output 输出幸 ...
- devops工具
工具类型及对应的不完全列举整理如下: 代码管理(SCM):GitHub.GitLab.BitBucket.SubVersion 构建工具:Ant.Gradle.maven 自动部署:Capistran ...
- BZOJ1398Vijos1382寻找主人 Necklace——最小表示法
题目描述 给定两个项链的表示,判断他们是否可能是一条项链. 输入 输入文件只有两行,每行一个由0至9组成的字符串,描述一个项链的表示(保证项链的长度是相等的). 输出 如果两条项链不可能同构,那么输出 ...
- P1495 曹冲养猪
原题链接 https://www.luogu.org/problemnew/show/P1495 这个题明显的中国剩余定理(孙子定理),如果有不懂孙子定理的点这个链接https://baike.bai ...
- 洛谷P1092 虫食算(算竞进阶习题)
模拟+dfs 这个题就三行,搜索的话我们从右向左,从上到下.. 如果是在1,2行我们就直接枚举0-n所有数,但是到了第三行,最直接的就是填上这一列上前两行的数的和modN,在此基础上判断该填的数有没有 ...