我想獲得用戶的用戶輸入我的OpenGL ES 2.0應用程序,但也有2個問題:
1)如何使軟鍵盤我的應用程序的前面?
2)如何捕捉它的輸入?
我嘗試使用此:顯示軟件鍵盤GLSurfaceView(並從中獲取輸入)
//OpenGL ES 2.0 view class
public class OGLES2View extends GLSurfaceView
{
private static final int OGLES_VERSION = 2;
private static Handler softKeyboardHandler;
private final static int SHOW_IME_KEYBOARD = 0;
private final static int HIDE_IME_KEYBOARD = 1;
private static EditText textEdit;
private static InputMethodManager imm;
private void setSoftKeyboardHandler()
{
softKeyboardHandler = new Handler()
{
public void handleMessage(Message msg)
{
switch(msg.what)
{
case SHOW_IME_KEYBOARD:
textEdit.requestFocus();
imm.showSoftInput(textEdit,inputMethodManager.SHOW_IMPLICIT);//Nothing happens
Log.i("GLVIEW","SHOW KEYBOARD");
break;
case HIDE_IME_KEYBOARD:
imm.hideSoftInput(textEdit, 0);
Log.i("GLVIEW","HIDE KEYBOARD");
break;
default:
break;
}
}
};
}
public OGLES2View(Context context)
{
super(context);
textEdit = new EditText(context);
setEGLContextClientVersion(OGLES_VERSION);
setRenderer(new OGLES2Renderer());
imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
setSoftKeyboardHandler();
}
public static void showIMEKeyboard()
{
softKeyboardHandler.sendEmptyMessage(SHOW_IME_KEYBOARD);
}
public static void hideIMEKeyboard()
{
softKeyboardHandler.sendEmptyMessage(HIDE_IME_KEYBOARD);
}
//In main activity class
private GLSurfaceView ogles2SurfaceView = null;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
...
ogles2SurfaceView = new OGLES2View(this);
setContentView(ogles2SurfaceView);
}
處理程序得到的消息,但是我沒有軟鍵盤。 爲了趕上文字我寫一些類
public class TextInputWatcher implements TextWatcher
而且
textEdit.addTextChangedListener(/*TextInputWatcher instance*/);
或者說,它捕獲的回inputed文本或回車鍵擴展文本編輯。
P.S.我有平板電腦 - 變壓器,所以有一個硬件鍵盤連接,我嘗試與它沒有,但沒有區別。所以獎金的問題 - 如果有一個硬件鍵盤,它會阻止軟件鍵盤彈出以及如何從它輸入?。
我不知道它是怎麼回事。你是否已經完成了該項目,如果沒有,是否有預覽? –