我已经根据自己的喜好在 xml 中创建了登录表单,并且我的共享偏好确实有效,但是当我将全屏添加到 java 类时,应用程序崩溃了。这是我的代码,任何帮助将不胜感激。
getWindow().requestFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
/*
* Check if we successfully logged in before.
* If we did, redirect to home page
*/
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getString("logged", "").toString().equals("logged")) {
Intent intent = new Intent(Password.this, Video.class);
startActivity(intent);
}
Button b = (Button) findViewById(R.id.loginbutton);
b.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText username = (EditText) findViewById(R.id.username);
EditText password = (EditText) findViewById(R.id.password);
if(username.getText().toString().length() > 0 && password.getText().toString().length() > 0 ) {
//------------------------------------Username below -------------------------------------Password below ---//
if(username.getText().toString().equals("username") && password.getText().toString().equals("password")) {
/*
* So login information is correct,
* we will save the Preference data
* and redirect to next class / home
*/
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("logged", "logged");
editor.commit();
Intent intent = new Intent(Password.this, Video.class);
startActivity(intent);
}
}
}
});
}
}