diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 31e79b1..7b92de0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ + android:theme="@style/Theme.OxFaceLogin.Splash"> diff --git a/app/src/main/java/com/ouxuan/oxface/MainActivity.java b/app/src/main/java/com/ouxuan/oxface/MainActivity.java index 3dec854..c07f169 100644 --- a/app/src/main/java/com/ouxuan/oxface/MainActivity.java +++ b/app/src/main/java/com/ouxuan/oxface/MainActivity.java @@ -3,21 +3,27 @@ package com.ouxuan.oxface; import androidx.appcompat.app.AppCompatActivity; import android.animation.ObjectAnimator; import android.os.Bundle; +import android.text.InputType; import android.view.MotionEvent; import android.view.View; -import android.widget.Button; import android.widget.EditText; +import android.widget.ImageView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private EditText editTextUsername; private EditText editTextPassword; - private Button buttonLogin; + private View buttonLogin; + private ImageView imageViewPasswordToggle; private Toast currentToast; // 用于管理Toast显示状态 + private boolean isPasswordVisible = false; // 密码显示状态 @Override protected void onCreate(Bundle savedInstanceState) { + // 在setContentView之前切换到正常主题,解决白屏问题 + setTheme(R.style.Theme_OxFaceLogin); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -34,12 +40,16 @@ public class MainActivity extends AppCompatActivity { // 设置按钮触摸动画 setupButtonAnimation(); + + // 设置密码显示/隐藏切换 + setupPasswordToggle(); } private void initViews() { editTextUsername = findViewById(R.id.editTextUsername); editTextPassword = findViewById(R.id.editTextPassword); buttonLogin = findViewById(R.id.buttonLogin); + imageViewPasswordToggle = findViewById(R.id.imageViewPasswordToggle); } private void setupLoginButton() { @@ -88,7 +98,7 @@ public class MainActivity extends AppCompatActivity { private boolean validateInput(String username, String password) { if (username.isEmpty()) { - showToast("请输入用户名"); + showToast("请输入登录账号"); editTextUsername.requestFocus(); return false; } @@ -132,4 +142,36 @@ public class MainActivity extends AppCompatActivity { currentToast = Toast.makeText(this, message, Toast.LENGTH_SHORT); currentToast.show(); } + + /** + * 设置密码显示/隐藏切换功能 + */ + private void setupPasswordToggle() { + imageViewPasswordToggle.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + togglePasswordVisibility(); + } + }); + } + + /** + * 切换密码的显示/隐藏状态 + */ + private void togglePasswordVisibility() { + if (isPasswordVisible) { + // 当前是显示状态,切换为隐藏 + editTextPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + imageViewPasswordToggle.setImageResource(R.drawable.ic_eye_closed); + isPasswordVisible = false; + } else { + // 当前是隐藏状态,切换为显示 + editTextPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); + imageViewPasswordToggle.setImageResource(R.drawable.ic_eye_open); + isPasswordVisible = true; + } + + // 保持光标在文本末尾 + editTextPassword.setSelection(editTextPassword.getText().length()); + } } \ No newline at end of file diff --git a/app/src/main/res/drawable/gradient_button_selector.xml b/app/src/main/res/drawable/gradient_button_selector.xml index 88cede7..02b5de1 100644 --- a/app/src/main/res/drawable/gradient_button_selector.xml +++ b/app/src/main/res/drawable/gradient_button_selector.xml @@ -2,12 +2,12 @@ - + @@ -15,12 +15,12 @@ - + diff --git a/app/src/main/res/drawable/ic_eye_closed.xml b/app/src/main/res/drawable/ic_eye_closed.xml new file mode 100644 index 0000000..1fe96fb --- /dev/null +++ b/app/src/main/res/drawable/ic_eye_closed.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_eye_open.xml b/app/src/main/res/drawable/ic_eye_open.xml new file mode 100644 index 0000000..b4bfd06 --- /dev/null +++ b/app/src/main/res/drawable/ic_eye_open.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/splash_background.xml b/app/src/main/res/drawable/splash_background.xml new file mode 100644 index 0000000..4b97f72 --- /dev/null +++ b/app/src/main/res/drawable/splash_background.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 4cb7931..97e2465 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,218 +1,242 @@ - - - - - - - - - - - - + - - + app:layout_constraintEnd_toEndOf="parent"> + + + - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - -