智能家居APP设计
welcome页面代码
package com.example.myapplication;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class Welcom extends AppCompatActivity {
Handler h;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcom1);
TextView tx=findViewById(R.id.textView);
h=new Handler(){
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
tx.setText(msg.what+"s");
}
};
new Thread(new Runnable() {
@Override
public void run() {
for(int i=5;i>0;i--){
Message msg=new Message();
msg.what=i;
h.sendMessage(msg);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Intent in=new Intent(Welcom.this,MainActivity.class);
startActivity(in);
}
}).start();
}
}
页面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/welcome"
tools:context=".Welcom">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="25dp"
android:textColor="#000000"
android:textSize="30dp"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></TextView>
</RelativeLayout>
主代码
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView wb=(WebView)findViewById(R.id.wd);
wb.loadUrl("https://www.baidu.com/");
wb.setWebViewClient(new WebViewClient());
}
}
页面
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="@drawable/bg"
tools:context=".MainActivity">
<WebView
android:id="@+id/wd"
android:layout_width="330dp"
android:layout_height="200dp"
android:layout_marginTop="165dp"
android:layout_marginLeft="20dp"
/>
<LinearLayout
android:id="@+id/li"
android:layout_below="@id/wd"
android:layout_width="200dp"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:layout_height="130dp"
android:layout_centerHorizontal="true"
>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="130dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="温度:"
android:textColor="#ffffff"
android:textSize="20dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="湿度:"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_weight="1"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="火警:"
android:textColor="#ffffff"
android:layout_weight="1"
android:textSize="20dp"
>
</TextView>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="130dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="40℃"
android:textColor="#ffffff"
android:textSize="20dp">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="98%"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_weight="1"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="监视"
android:textColor="#ffffff"
android:layout_weight="1"
android:textSize="20dp"
>
</TextView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_below="@id/li"
android:layout_width="300dp"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:layout_height="40dp">
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="备用"
android:background="#05DEDF"></Button>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="备用"
android:background="#05DEDF"></Button>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="备用"
android:background="#05DEDF"></Button>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="备用"
android:background="#05DEDF"></Button>
<Button
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="备用"
android:background="#05DEDF"></Button>
</LinearLayout>
</RelativeLayout>