艺术名画网站怎么建设,快三直播十大平台直播间,wordpress 新建侧边栏,国外手机设计网站当大家 用Android 应用 操作时#xff0c;会发现有很多应用要登陆名和密码#xff0c;而且#xff0c;它们都能记住密码#xff0c;当你退出 #xff0c;再次登陆时#xff0c;你们帐号密码会自动添加上去。例#xff1a;布局文件 相信都能做出来 就不一一介绍 了。下面…当大家 用Android 应用 操作时会发现有很多应用要登陆名和密码而且它们都能记住密码当你退出 再次登陆时你们帐号密码会自动添加上去。例布局文件 相信都能做出来 就不一一介绍 了。下面直接来正文。创建一个LoginActivity 文件public class LoginActivity extends Activity { // 声明 获取的用户名与密码的组件public EditText edit_name, edit_pass;// 声明登陆按钮对象public Button btn_login;// 声明CheckBox组件对象public CheckBox box_remember;// 创建业务对象public FileService fileService; Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); // 设置显示视图setContentView(R.layout.activity_login); // 实例化业务对象fileService new FileService(this); // 根据id名称获取相应组件对象edit_name (EditText) findViewById(R.id.name_value);edit_pass (EditText) findViewById(R.id.pass_value);btn_login (Button) findViewById(R.id.but);box_remember (CheckBox) findViewById(R.id.cobx); // 给按钮注册事件btn_login.setOnClickListener(new MyOnClickListener()); // 回显数据Map map fileService.readFile(private.txt);if (map ! null) {edit_name.setText(map.get(name));edit_pass.setText(map.get(pass));} } Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.login, menu);return true;} // 内部类class MyOnClickListener implements View.OnClickListener {Overridepublic void onClick(View v) {int id v.getId(); // 判断当前点击组件是否是 按钮if (id btn_login.getId()) { // 获取用户名与密码String name edit_name.getText().toString();String pass edit_pass.getText().toString(); // 判断用户名与密码是否为空if (TextUtils.isEmpty(name) || TextUtils.isEmpty(pass)) {Toast.makeText(LoginActivity.this, 用户名或者密码不能为空,Toast.LENGTH_LONG).show();return;} else { // 如果记住密码勾选上了if (box_remember.isChecked()) {// 进行保存// 调用业务对象的业务方法LoginActivity.this.fileService.saveToRom(name, pass,private.txt);Toast.makeText(LoginActivity.this, 用户名和密码需要保存,Toast.LENGTH_LONG).show(); } else {// 不保存Toast.makeText(LoginActivity.this, 用户名和密码不需要保存,Toast.LENGTH_LONG).show();} } } } }} public class FileService {//上下方对象public Context context;public FileService(Context context){this.context context;}/*** 住手机内存卡上存储 用户名与密码的操作***/public boolean saveToRom(String name,String pass,String fileName){//上下文对象的apitry {//通过 openFileOutput()方法获取一个文件 的输出流对象FileOutputStream fos context.openFileOutput(fileName, Context.MODE_PRIVATE);//拼接用户名与密码String result name : pass;//写入fos.write(result.getBytes());fos.flush();fos.close();} catch (Exception e) {e.printStackTrace();return false;}return true;}//读取数据操作public Map readFile(String fileName){Map map null;try {FileInputStream fis context.openFileInput(fileName);String value StreanTools.getValue(fis);String values[] value.split(:);if(values.length 0){map new HashMap();map.put(name, values[0]);map.put(pass, values[1]);}} catch (Exception e) {e.printStackTrace();}return map;} } public class StreanTools {public static String getValue(FileInputStream fis)throws Exception{//字节 流输出流对象ByteArrayOutputStream stream new ByteArrayOutputStream();byte[] buffer new byte[1024];int length -1;while((length fis.read(buffer)) ! -1){stream.write(buffer, 0, length);}stream.flush();stream.close();String value stream.toString();return value;}}