我正在尝试获取 Android 应用程序的登录屏幕,到目前为止这是我的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:orientation="vertical">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:inputType="text"
android:singleLine="true"
android:imeOptions="actionNext">
<requestFocus />
</EditText>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:singleLine="true"
android:imeOptions="actionDone" />
<Button
android:id="@+id/buttonLaunchTriage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/login" />
</LinearLayout>
</RelativeLayout>
当我尝试运行它时,键盘会显示正确的键,但是当我在输入密码后尝试按完成时,没有任何反应。我正在使用它来处理按钮按下:
private void setupLoginButton() {
Button launchButton = (Button) findViewById(R.id.buttonLaunchTriage);
launchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText username = (EditText) findViewById(R.id.patient_start_userName_value);
EditText password = (EditText) findViewById(R.id.patient_start_password_value);
try {
if(TriageApplicationMain.validateUser(username.getText().toString(),password.getText().toString(),getApplicationContext()))
{
Toast.makeText(StartActivity.this,
"Launching Triage Application", Toast.LENGTH_SHORT)
.show();
startActivity(new Intent(StartActivity.this, MainActivity.class));
}
else
{
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
StartActivity.this);
// set dialog message
alertDialogBuilder
.setMessage("Incorrect Credentials")
.setCancelable(false)
.setPositiveButton("OK",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
我知道这是很多代码,但如果有人可以在这里帮助我,那就太好了。这是一个学校项目。
PS:我已经在谷歌上搜索了整整一个小时才发布这个,所以请不要批评我没有这样做。如果您发现有用的链接,请分享。
最佳答案
只需将 android:inputType="..."
添加到您的 EditText。它会工作的! :)
关于Android imeOptions ="actionDone"不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27007040/