android - 输入文本后如何退出editText?

标签 android android-layout android-edittext

我已经为我的程序准备了一个入口屏幕,我已经在其中放置了一个编辑文本和 ImageViews。现在的问题是我可以通过虚拟键盘在编辑文本中键入文本,但问题是在我完成之后我的文本然后我不能从编辑文本中出来,光标只停留在编辑文本框。 我在下面有一个 imageView 可以点击以继续处理表格,但当时无法点击。请帮忙!!!

我的代码是

我的xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
         android:id="@+id/begin_"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="170dp"
         android:layout_marginTop="220dp"
         android:src="@drawable/begin" />

    <ImageView
        android:id="@+id/enter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="30dp"
        android:src="@drawable/enter_name" />

     <ImageView
        android:id="@+id/roof"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/roof" />

     <EditText
         android:id="@+id/editText2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="180dp"
         android:layout_marginTop="180dp"
         android:ems="8"
         android:inputType="textMultiLine" 
         android:imeOptions="actionDone"/>
</FrameLayout>

我的主要java类

package game.pack;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Begin extends Activity implements View.OnClickListener  {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

            setContentView(R.layout.entry);

        ImageView begin = (ImageView) findViewById(R.id.begin_);
        begin.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch(v.getId()) {
        case R.id.begin_:
            setContentView(new SushiMain(this));
            break;
        default:
            break;
        }
    }
}

我的 android list 是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="game.pack"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity
            android:name=".FrontScreen"
            android:screenOrientation="landscape"
            android:label="@string/app_name" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".Begin"
            android:screenOrientation="landscape"
            android:label="@string/app_name" 
            >
          <intent-filter>
                  <action android:name="begingame" />
                  <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>

        <activity
            android:name=".Sushitap"
            android:screenOrientation="landscape"
            android:label="@string/app_name" >

        <intent-filter>
                <action android:name="gameover" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

最佳答案

使用View.OnKeyListener当在 EditText 中键入后按下 ENTER KEY PRESSED 时,EditText 从 EditText 中删除焦点:

ditText.setOnKeyListener(onSoftKeyboardDonePress);

    private View.OnKeyListener onSoftKeyboardDonePress=new View.OnKeyListener() 
    {
        public boolean onKey(View v, int keyCode, KeyEvent event) 
        {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            {
                 // code to hide the soft keyboard
                 EditTexst.clearFocus();
                 EditTexst.requestFocus(EditText.FOCUS_DOWN);            
            }
            return false;
        }
    };

关于android - 输入文本后如何退出editText?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11259912/

相关文章:

jquery - 移动开发和屏幕尺寸

android - PhoneGap 安卓 : keyboard overlaps input field

java - Android Canvas 锁定抛出 IllegalArgumentException

java - Android - requestFocus 关闭键盘

java - 登录功能中出现意外的 token 错误

java - 如何在 Android 中通过 POST 请求查询 Web 服务?

Android:居中图像

Android EditText——查找红线文本和建议词列表

Android AppCompat SearchView EditText 在 Lollipop 之前缺少底线

java - 尝试使用多个 EditText 进行 Catch,并与 OnClick 进行交互