android:textSize=“20sp”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_weight=“0.1”
android:gravity=“end”/>
<EditText
android:id=“@+id/input2”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“2”
android:hint=" "/>
<CheckBox
android:id=“@+id/remember_button”
android:layout_width=“wrap_content”
android:layout_marginLeft=“10dp”
/>
<TextView
android:id=“@+id/remember_text”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:layout_weight=“1”
android:textStyle=“bold”
android:text=“是否保存本次密码”/>
<ProgressBar
android:id=“@+id/progress”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
style=“?android:attr/progressBarStyleHorizontal”
android:max=“250” />
<Button
android:id=“@+id/login_button”
android:text=“点击注册进入”
android:textSize=“25sp”
android:background=“#add8e6”
android:layout_marginLeft=“15dp”
android:layout_marginRight=“15dp”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”/>
second.main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
android:background=“@drawable/bj”
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<TextView
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“欢迎来到贪吃蛇”
android:gravity=“center”
android:textSize=“30sp”
/>
<ImageButton
android:id=“@+id/button_start”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_marginLeft=“51dp”
android:layout_marginTop=“190dp”
android:background=“@drawable/circle1” />
<ImageButton
android:id=“@+id/button_difficulty”
android:background=“@drawable/circle2”
android:layout_marginTop=“192dp”
android:layout_marginLeft=“235dp”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content” />
<ImageButton
android:id=“@+id/button_music”
android:background=“@drawable/circle3”
android:layout_below=“@id/button_start”
android:layout_marginLeft=“51dp”
android:layout_marginTop=“120dp”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content” />
<ImageButton
android:id=“@+id/button_about”
android:background=“@drawable/circle4”
android:layout_below=“@id/button_difficulty”
android:layout_marginTop=“120dp”
android:layout_marginLeft=“235dp”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content” />
MainActivity.java
package com.example.greedy;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
Button button;
EditText edit1,edit2;
CheckBox checkbox;
ProgressBar bar;
SharedPreferences pref;
SharedPreferences.Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button) findViewById(R.id.login_button);
edit1=(EditText) findViewById(R.id.input1);
edit2=(EditText) findViewById(R.id.input2);
checkbox=(CheckBox) findViewById(R.id.remember_button);
bar=(ProgressBar) findViewById(R.id.progress);
pref= PreferenceManager.getDefaultSharedPreferences(this);
boolean isRemember=pref.getBoolean(“rem”,false); //用于给是否保存密码赋值
if(isRemember) {
//将账号和密码设置到文本框中
String account=pref.getString(“account”,“”);
String password=pref.getString(“password”,“”);
edit1.setText(account);
edit2.setText(password);
checkbox.setChecked(true);
}
button.setOnClickListener(this);
}
@Override
public void onClick(View v){
/* new Thread(new Runnable(){ //开启线程运行进度条
@Override
public void run() {
for (int i = 0; i < 25; i++) {
int progress = bar.getProgress();
progress = progress + 10;
bar.setProgress(progress);
}
}
}).start();*/
String account=edit1.getText().toString();
String password=edit2.getText().toString();
if(account.equals(“admin”) && password.equals(“123456”)) {
editor = pref.edit();
if(checkbox.isChecked()) {
editor.putBoolean(“rem”,true);
editor.putString(“account”,account);