改变值,可显示zai在
在theves下面的两个value都要增加名字代码
<item name="windowActionBar">false</item><item name="android:windowNoTitle">true</item><item name="android:windowFullscreen">true</item>
设置背景图片 在avtivity里面添加background
<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"android:background="@drawable/splash"tools:context=".SplashActivity">
并且在AndroidMainifest里面用iintent
建立一个新的activity,添加背景图,定时器
添加控件,并且设置名字,hint隐藏密码
inputtype输入密码类型
判断用户名和密码
package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.QuickContactBadge;
import android.widget.Toast;public class LoginActivity extends AppCompatActivity {private EditText dtName,dtPasswd;private Button btnLogin,btnPasswd;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_login);}private void initView(){dtName=findViewById(R.id.dtLoginName);dtPasswd=findViewById(R.id.dtLoginPasswd);btnLogin=findViewById(R.id.btnLogin);btnPasswd=findViewById(R.id.btnPasswd);btnPasswd.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {finish();}});btnLogin.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String sName=dtName.getText().toString();String sPasswd=dtPasswd.getText().toString();if((!sName.equals("admin"))||(!sPasswd.equals("123456"))){Toast.makeText(LoginActivity.this,"用户名或者密码错错误",Toast.LENGTH_SHORT).show();return;}Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();}});}}
跳转到主窗口 startactivity
btnLogin.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {String sName=dtName.getText().toString();String sPasswd=dtPasswd.getText().toString();if((!sName.equals("admin"))||(!sPasswd.equals("123456"))){Toast.makeText(LoginActivity.this,"用户名或者密码错错误",Toast.LENGTH_SHORT).show();return;}Toast.makeText(LoginActivity.this,"登陆成功",Toast.LENGTH_SHORT).show();Intent intent=new Intent(LoginActivity.this,MainActivity.class);startActivity(intent);}});
启动web服务器
要打开文件,bin目录下,一直挂着
创建线程
private void checkWebServe(){String sUrl="http://10.107.24.12:8080/newsIndex.json";Thread t=new Thread(new Runnable() {@Overridepublic void run() {try {URL url=new URL(sUrl);HttpURLConnection urlConn=(HttpURLConnection) url.openConnection();urlConn.setRequestMethod("GET");InputStream ins=urlConn.getInputStream();if(null==ins){}else {byte[] date=new byte[1000];int ret=ins.read(date,0, date.length);String s=new String(date,0,ret);Log.d("test",s);ins.close();}}catch (Exception e){e.printStackTrace();}}});}
需调用
<uses-permission android:name="android.permission.INTERNET"/>
明文传输
android:usesCleartextTraffic="true"
调用checkWebServe
等待一秒
t.start();try {t.join(1000);}catch (Exception e){}