Android imeOptions ="actionDone"不工作

标签 android imeoptions

我正在尝试获取 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/

相关文章:

java - URIBeacon 的 BeaconLayout 是什么?

android EditText imeOptions OnClick

android - 使用 GO 打开键盘

android - 当用户按下键盘上的完成按钮时如何触发事件

java - 在 OnFocusChanged Listener 中保持对 Edittext 的关注

android - actionNext(或任何 ImeOption)不适用于我的 Edittext,当选择此特定文本字段时,我也无法选择任何其他文本字段

java - 我可以在布局或组件盒上设置凸起的边缘吗?

android - 什么是 com.google.android.gms.version?

android - 更新 google play 服务(8.1 至 8.3)后应用程序无法安装

android - 如何使用 Android FirebaseUI 从 Firebase 分页查询