Adroid登录界面
来源:互联网 发布:时间轴数据库 编辑:程序博客网 时间:2024/06/05 05:41
Acivity_login:代码
<RelativeLayout xmlns:Android="http://schemas.Android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/deer"
android:padding="64dp"
tools:context="cn.edu.bzu.login.LoginActivity">
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/edit_text"
android:drawableLeft="@drawable/icon_user"
android:drawablePadding="10dp"
android:ems="10"
android:hint="请输入账号">
<requestFocus />
</EditText>
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etName"
android:background="@android:drawable/edit_text"
android:drawableLeft="@drawable/icon_pass"
android:drawablePadding="10dp"
android:ems="10"
android:hint="请输入密码"
android:inputType="textPassword">
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/etPassword">
<CheckBox
android:id="@+id/cbIsRememberPass"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="记住密码"
android:textSize="20sp" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/holo_blue_dark"
android:onClick="login"
android:text="登录" />
</LinearLayout>
</RelativeLayout>
Activity_Main代码
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cn.edu.bzu.login.MainActivity">
<TextView
android:text="Welcome you"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textSize="40sp"
android:layout_marginTop="263dp"
android:id="@+id/textView"/>
</RelativeLayout>
LoginActivity.Java代码
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v4.content.SharedPreferencesCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
private EditText etName;
private EditText etPassword;
private CheckBox cbIsRememberPass;
private SharedPreferences sharedPreferences;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initViews();
sharedPreferences=getSharedPreferences("rememberpassword", Context.MODE_PRIVATE);
boolean isRemember=sharedPreferences.getBoolean("rememberpassword",false);
if(isRemember){
String name=sharedPreferences.getString("name","");
String password=sharedPreferences.getString("password","");
etName.setText(name);
etPassword.setText(password);
cbIsRememberPass.setChecked(true);
}
}
private void initViews(){
etName= (EditText) findViewById(R.id.etName);
etPassword= (EditText) findViewById(R.id.etPassword);
cbIsRememberPass= (CheckBox) findViewById(R.id.cbIsRememberPass);
}
public void login(View view){
String name=etName.getText().toString();
String password=etPassword.getText().toString();
if("admin".equals(name)&&"123456".equals(password)){
SharedPreferences.Editor editor=sharedPreferences.edit();
if(cbIsRememberPass.isChecked()){
editor.putBoolean("rememberpassword",true);
editor.putString("name",name);
editor.putString("password",password);
}else{
editor.clear();
}
editor.commit();
Intent intent=new Intent(this,MainActivity.class);
startActivity(intent);
finish();
}else {
Toast.makeText(this,"账号或密码有误",Toast.LENGTH_LONG).show();
}
}
}
MainActivity.Java:代码保持默认代码
0 0
- Adroid登录界面
- Adroid 界面绘制实现
- Adroid UI 界面绘制原理分析
- Adroid UI 界面绘制原理分析
- Adroid UI 界面绘制原理分析
- Adroid UI 界面绘制原理分析
- adroid
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 登录界面
- 谷歌人工智能深度解剖:从HAL的太空漫游到AlphaGo,AI的春天来了
- 登录拦截器的实现
- 数组中的逆序对——分治法(归并排序的应用)
- 为什么java.util.concurrent 包里没有并发的ArrayList实现?
- 2017XDU初赛网络赛
- Adroid登录界面
- Unique Paths (第九周 动态规划)
- java实现文件断点下载
- Object类型知识总结,你掌握了多少?
- The Solution to Leetcode 541 Reverse String II
- python大规模爬取京东
- SPFA算法学习
- Leetcode-标签为Tree 104.Maximum Depth of Binary Tree
- linux 下 Socket原理及实现