java,// MainActivity.java,package com.example.loginapp;,,import android.os.Bundle;,import android.view.View;,import android.widget.Button;,import android.widget.EditText;,import android.widget.Toast;,import androidx.appcompat.app.AppCompatActivity;,,public class MainActivity extends AppCompatActivity {, private EditText usernameEditText, passwordEditText;, private Button loginButton, registerButton;,, @Override, protected void onCreate(Bundle savedInstanceState) {, super.onCreate(savedInstanceState);, setContentView(R.layout.activity_main);,, usernameEditText = findViewById(R.id.username);, passwordEditText = findViewById(R.id.password);, loginButton = findViewById(R.id.login);, registerButton = findViewById(R.id.register);,, loginButton.setOnClickListener(new View.OnClickListener() {, @Override, public void onClick(View v) {, String username = usernameEditText.getText().toString();, String password = passwordEditText.getText().toString();, if (validateLogin(username, password)) {, Toast.makeText(MainActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();, } else {, Toast.makeText(MainActivity.this, "Invalid Credentials", Toast.LENGTH_SHORT).show();, }, }, });,, registerButton.setOnClickListener(new View.OnClickListener() {, @Override, public void onClick(View v) {, String username = usernameEditText.getText().toString();, String password = passwordEditText.getText().toString();, if (registerUser(username, password)) {, Toast.makeText(MainActivity.this, "Registration Successful", Toast.LENGTH_SHORT).show();, } else {, Toast.makeText(MainActivity.this, "Registration Failed", Toast.LENGTH_SHORT).show();, }, }, });, },, private boolean validateLogin(String username, String password) {, // Add your validation logic here, return true; // Placeholder return value, },, private boolean registerUser(String username, String password) {, // Add your registration logic here, return true; // Placeholder return value, },},
`,,
`xml,,,,,,,,,,,,
``onTouchListener
和onDragListener
来实现拖拽还原功能。当用户触摸并拖动按钮时,通过监听器更新按钮的位置,实现拖拽效果;当手指抬起时,将按钮位置重置到初始位置,实现还原功能。RippleDrawable
或自定义View。以下是一个简单的示例代码:,,``java,// 在res/drawable目录下创建一个ripple_effect.xml文件,,,,,,,,,// 在布局文件中使用该drawable作为背景,,
``,,这段代码创建了一个带有水波纹效果的按钮,当用户点击按钮时,会显示一个扩散的水波纹动画。Powered By Z-BlogPHP 1.7.3