布局文件
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="0dp"
android:layout_height="80dp"
android:text="数据展示"
android:textSize="20dp"
android:background="#7A696B6B"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="80dp"
android:text="视频记录"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/button" />
<Button
android:id="@+id/button3"
android:layout_width="0dp"
android:layout_height="80dp"
android:text="视频聊天"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="@+id/button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="@+id/button2" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/button2"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:id="@+id/image1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@id/edit1"
app:layout_constraintLeft_toLeftOf="parent"
android:src="@mipmap/p3"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/edit1"
android:textSize="20dp"
android:text="温度:36.2 C"
android:textColor="@color/colorAccent"
app:layout_constraintLeft_toRightOf="@id/image1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/button2"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/edit2"
android:textSize="20dp"
android:text="湿度:25 %rh"
android:textColor="@color/colorAccent"
app:layout_constraintLeft_toRightOf="@id/image1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/edit1"
app:layout_constraintBottom_toTopOf="@id/button2"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/edit3"
android:textSize="20dp"
android:text="co浓度:25 mol/L"
android:textColor="@color/colorAccent"
app:layout_constraintLeft_toRightOf="@id/image1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/edit1"
app:layout_constraintBottom_toTopOf="@id/edit2"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/edit4"
android:textSize="20dp"
android:text="帽子压力大小:10 Pa"
android:textColor="@color/colorAccent"
app:layout_constraintLeft_toRightOf="@id/image1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/edit2"/>
</androidx.constraintlayout.widget.ConstraintLayout>
最后加一行
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
Java文件
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button2=findViewById(R.id.button2);
final Uri uri=Uri.parse("https://www.bilibili.com/");
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(Intent.ACTION_VIEW,uri);
startActivity(intent);
}
});
}
}
图片文件
colors文件
<?xml version="1.0" encoding="UTF-8"?>
-<resources>
<color name="colorPrimary">#696B6B</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>