Android studio的欢迎界面本来还有,今天运行时没有了
页面布局和逻辑代码也都在
package com.example.test06;
import androidx.appcompat.app.AppCompatActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.TextView;
public class Welcome extends AppCompatActivity {
SharedPreferences sp;
TextView showhello;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
sp = this.getSharedPreferences("username", this.MODE_PRIVATE); //获取sharepreferences
showhello = this.findViewById(R.id.mainword); //显示欢迎
showhello.setText("欢迎你!"+sp.getString("Loginname","")); //获取用户名
}
}
这是对应的布局文件activity_welcome.xml
<?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=".Welcome">
<TextView
android:id="@+id/mainword"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textSize="22dp"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>