今天完成了密码找回界面
代码:
<?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="@mipmap/qw" android:orientation="vertical" tools:context=".retrieve_Activity"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="fitStart" android:src="@mipmap/top" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginTop="150dp" android:layout_marginRight="30dp" android:background="@drawable/background_res" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/name" /> <EditText android:id="@+id/main2_name" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginLeft="10dp" android:background="@null" android:hint="手机号/邮箱" android:imeOptions="actionSearch" android:maxLength="10" android:maxLines="1" android:singleLine="true" tools:ignore="TouchTargetSizeCheck" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2px" android:layout_marginTop="5dp" android:layout_marginBottom="20dp" android:background="#f3f3f3" /> </LinearLayout> <Button android:id="@+id/main2_res" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="50dp" android:layout_marginTop="340dp" android:layout_marginRight="50dp" android:background="@drawable/button_1" android:onClick="find_pas" android:text="找回" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:layout_marginTop="420dp" android:layout_marginRight="30dp" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@drawable/password" /> <TextView android:id="@+id/main2_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginLeft="30dp" android:text="密码为" /> </LinearLayout> <View android:layout_width="match_parent" android:layout_height="2px" android:layout_marginTop="5dp" android:layout_marginBottom="20dp" android:background="#f3f3f3" /> </LinearLayout> </RelativeLayout>
Java文件为
package com.example.math; /* * 找回界面*/ import static android.widget.Toast.LENGTH_SHORT; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import com.example.math.repositiory.user_res; public class retrieve_Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_retrieve); } public void find_pas(View view) { EditText main2_name = findViewById(R.id.main2_name); TextView main2_pas = findViewById(R.id.main2_password); Handler handler = new Handler(); new Thread() { @Override public void run() { String pas; try { pas = user_res.findPassword(main2_name.getText().toString()); } catch (Exception e) { throw new RuntimeException(e); } handler.post(() -> main2_pas.setText(pas)); } }.start(); Toast.makeText(getApplicationContext(), "找回成功", Toast.LENGTH_LONG).show(); } }
标签:Toast,widget,pas,04,main2,09,2023,import,android From: https://www.cnblogs.com/JJTyyds/p/17301025.html