一、新建一个layout5.xml,同样换为constriant模式。
二、拖动两个Button到预览界面,第一个按钮名字改为DISPLAY WEBPAGE,第二个按钮名字改为MAKE A CALL。第一个按钮连接上左右。width改为match。第二个按钮连接左右,上方连第一个按钮的下方。width改为match,与第一个按钮的距离改为16。切换到text模式,在第一个按钮下添加android:onClick="openWebpage";第二个按钮下添加android:onClick=makecall";alt+enter就在.java文件下建了这两个函数。
三、切换到main.java:
效果就是,点击DISPLAY WEBPAGE按钮会跳到苹果界面。
效果就是点击按钮,会出现以下界面
layout5.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/linearLayout3"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button11"
android:onClick="openWebpage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="DISPLAY WEBPAGE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button12"
android:onClick="makecall"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:text="MAKE A CALL"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button11" />
</android.support.constraint.ConstraintLayout>
main.xml:
package com.example.aimee.aimeetest1;
import android.content.Intent;
import android.net.Uri;
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.layout5);
}
public void JumpToScreen2(View view) {
Intent i=new Intent(this,Layout4Activity.class);
startActivity(i);
}
public void openWebpage(View view) {
Intent i=new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.baidu.com"));
startActivity(i);
}
public void makecall(View view) {
Intent i=new Intent(Intent.ACTION_VIEW,Uri.parse("tel:***********"));
startActivity(i);
}
}