tôi đang cố gắng để có được một màn hình đăng nhập cho một ứng dụng Android và cho đến nay đây là mã của tôi:imeOptions Android = "actionDone" không làm việc
<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>
Khi tôi cố gắng chạy nó, bàn phím cho thấy bên phải nhưng khi tôi cố gắng nhấn xong sau khi nhập mật khẩu, không có gì xảy ra. Tôi đang sử dụng tính năng này để xử lý nút nhấn:
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();
}
}
});
}
Tôi biết điều này rất nhiều mã, nhưng nếu có ai có thể giúp tôi ở đây thì sẽ rất tuyệt. Đây là cho một dự án trường học.
PS: Tôi đã tìm kiếm thông qua Google trong một giờ vững chắc trước khi đăng bài này vì vậy xin đừng chỉ trích vì đã không làm điều đó. Nếu bạn tìm thấy một liên kết hữu ích thì hãy chia sẻ.
gì chính xác là bạn mong đợi từ "làm" trong bàn phím mềm đầu vào? tự ẩn bàn phím hoặc tiến hành đăng nhập? – waqaslam
tôi đã gặp phải vấn đề tương tự, bạn sẽ phải thêm: android: imeActionLabel = "Xong" android: singleLine = "true" đây là câu trả lời http://stackoverflow.com/questions/5578991/actiondone -imeoption-doesnt-work-on-edittext-in-android-2-3/5579944 # 5579944 –