安卓开发登录界面代码
时间: 2023-09-28 07:06:30 浏览: 41
以下是一个简单的安卓开发登录界面的代码示例:
```java
package com.example.dx.mylogin;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private EditText etUsername;
private EditText etPassword;
private Button btnLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
etUsername = findViewById(R.id.et_username);
etPassword = findViewById(R.id.et_password);
btnLogin = findViewById(R.id.btn_login);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = etUsername.getText().toString();
String password = etPassword.getText().toString();
if (username.equals("admin") && password.equals("123456")) {
// 登录成功,跳转到登录成功界面
Intent intent = new Intent(MainActivity.this, LoginSuccessfullyActivity.class);
startActivity(intent);
} else {
// 登录失败,显示提示信息
Toast.makeText(MainActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
}
}
});
}
}
```
这段代码实现了一个简单的登录界面,包括一个用户名输入框、一个密码输入框和一个登录按钮。当用户点击登录按钮时,会获取输入的用户名和密码,如果用户名为"admin"且密码为"123456",则登录成功,跳转到登录成功界面(LoginSuccessfullyActivity);否则,显示一个提示信息,提示用户名或密码错误。
请注意,这只是一个简单的示例代码,实际的登录界面可能需要更多的功能和验证逻辑。
#### 引用[.reference_title]
- *1* *2* *3* [安卓开发——登录界面](https://blog.csdn.net/qq_33198758/article/details/82587330)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)