minitwittersimulate

protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_login);
	pref = PreferenceManager.getDefaultSharedPreferences(this);
	accountEdit = (EditText) findViewById(R.id.account);
	passwordEdit = (EditText) findViewById(R.id.password);
	rememberPass = (CheckBox) findViewById(R.id.remeber_pass);
	login = (Button) findViewById(R.id.login);
	boolean isRemember = pref.getBoolean("remember_password", false);
	if (isRemember) {
		// 将账号和密码都设置到文本框中
		String account = pref.getString("account", "");
		String password = pref.getString("password", "");
		accountEdit.setText(account);
		passwordEdit.setText(password);
		rememberPass.setChecked(true);
	}

      
	login.setOnClickListener(new OnClickListener() {
		@Override
		public void onClick(View v) {
			String account = accountEdit.getText().toString();
			String password = passwordEdit.getText().toString();
			if (account.equals("admin") && password.equals("123456")) {
				editor = pref.edit();
				if (rememberPass.isChecked()) { // 检查复选框是否被选中
					editor.putBoolean("remember_password", true);
					editor.putString("account", account);
					editor.putString("password", password);
				} else {
					editor.clear();
				}
				editor.commit();
				Intent intent = new Intent(LoginActivity.this, MainActivity.class);
				startActivity(intent);
	            finish(); 
				
			} else {
				Toast.makeText(LoginActivity.this, "account or password is invalid", Toast.LENGTH_SHORT).show();
			}
		}
	});

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

  <TextView
        android:id="@+id/tvRegist"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="18dp"
        android:text="@string/tvRegister"
        android:autoLink="all"
        android:textColorLink="#FF0066CC" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="24dp"
        android:src="@drawable/panda" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="28dp"
        android:src="@drawable/icon" />




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值