我已經構建了我的第一個應用程序,我想密碼保護它。將密碼存儲在Java文件中並且該方法需要儘可能簡單,因爲我在這個應用程序之前沒有java甚至xml的經驗。我有過幾次嘗試,但都失敗了,所以我希望有人能幫助我。密碼保護我的Android應用程序(簡單的方式)
我曾與一個EditText字段中創建的佈局:
<EditText
android:id="@+id/passwordedittext"
android:layout_width="200dp"
android:layout_height="50dp"
android:inputType="textPassword"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp">
<requestFocus />
和一個提交按鈕:
<Button
android:id="@+id/submitbutton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="40dp"
android:background="@drawable/bgo"
android:clickable="true"
android:layout_gravity="right|center_horizontal"
android:layout_marginRight="20dp"/>
Java文件:
package com.berry;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
public class password extends Activity{
MediaPlayer mpbuttonclick;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
setContentView(R.layout.password);
mpbuttonclick = MediaPlayer.create(this, R.raw.keypress);
Button sumbitButton = (Button) findViewById(R.id.submitbutton);
sumbitButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
EditText passwordEditText = (EditText) findViewById(R.id.passwordedittext);
if(passwordEditText.getText().toString()=="MyPasswordHere"){
startActivity(new Intent("com.berry.intro"));
mpbuttonclick.start();
}}});
}}
謝謝你做的竅門! – SuperKombol 2012-02-19 17:32:15