安卓开发日记21
主要使用了ScrollView包裹着一个垂直方向的LinearLayout,其中包含了一些TextView、EditText和一个登录按钮。
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class SignInActivity extends AppCompatActivity {
private EditText inputEmail, inputPassword;
private Button buttonSignIn;
private TextView textCreateNewAccount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sign_in);
inputEmail = findViewById(R.id.inputEmail);
inputPassword = findViewById(R.id.inputPassword);
buttonSignIn = findViewById(R.id.buttonSignIn);
textCreateNewAccount = findViewById(R.id.textCreateNewAccount);
buttonSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
signIn();
}
});
textCreateNewAccount.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Handle creating new account
Toast.makeText(SignInActivity.this, "Create new account clicked", Toast.LENGTH_SHORT).show();
}
});
}
private void signIn() {
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
if (TextUtils.isEmpty(email)) {
inputEmail.setError("Please enter your email");