我正在尝试在andengine游戏之上创建一个EditText来充当游戏聊天室.我使用的方法在Android 2.2.1 IDEOS 2,Emulator Android 2.1,Emulator Android 2.2,Emulator Android 2.3上运行良好.
更新25/APR/2012:最近在三星Galaxy S SGH-T959 Android 2.1-Update1上进行了测试,除了小的对齐问题外它工作正常,这是三星Android 2.3的问题.
以下设备不会在andengine游戏活动之上显示EditText控件:
这就是我在游戏活动中所做的事情
chatEditText = new EditText(this);
chatEditText.setSingleLine(true);
chatEditText.setId(1);
chatEditText.setHint(" ");
tableLayout = new TableLayout(this);
tableLayout.setVerticalGravity(Gravity.BOTTOM);
tableLayout.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
tableLayout.setHorizontalGravity(Gravity.CENTER_HORIZONTAL);
tableLayout.setPadding(25, 25, 25, 308);
tableLayout.addView(chatEditText);
LayoutParams lp = new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
this.addContentView(tableLayout, lp);
tableLayout.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
要显示/隐藏控件,我将根据需要使用处理程序将其可见性设置为View.VISIBLE或View.GONE.
以上适用于IDEOS 2 Android 2.2.1和仿真器但不适用于三星Galaxy 551,三星Galaxy S 5360,其他设备需要进行测试.请帮忙.
这里描述了上面的方法:AndEngine论坛,在andengine中显示UI 另一种方法是建议的,其中一个Popup对话框将在这里显示EditText AndEngine帮助类输入文本,但这不适合我的用例.
想使用标准的EditText,否则唯一的出路就像是在AndEngine中实现自己的假键盘和假输入精灵,但硬件和国际键盘可能无法使用.任何帮助将不胜感激.
user-interface android andengine android-edittext android-2.3-gingerbread