我有一个布局,其中包含一些像这样的视图:
<LinearLayout>
<TextView...>
<TextView...>
<ImageView ...>
<EditText...>
<Button...>
</linearLayout>
Run Code Online (Sandbox Code Playgroud)
如何以EditText编程方式设置焦点(显示键盘)?
我已经尝试了这个,只有当我Activity正常启动时它才有效,但是当我在a中启动它时TabHost,它不起作用.
txtSearch.setFocusableInTouchMode(true);
txtSearch.setFocusable(true);
txtSearch.requestFocus();
Run Code Online (Sandbox Code Playgroud) 我试图在一个Activity中强制打开Soft Keyboard并抓取输入的所有内容,因为我想自己处理输入,我没有EditText.目前我已经尝试了这个,但它不起作用.我想在mAnswerTextView下打开Soft Keyboardto(注意:它是TextView而不是EditText).
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// only will trigger it if no physical keyboard is open
mgr.showSoftInput(mAnswerTextView, InputMethodManager.SHOW_IMPLICIT);
Run Code Online (Sandbox Code Playgroud)
最近在开发应用程序时,我遇到了一个问题.我在谷歌搜索了很多,但找不到任何解决方案.最后,我遇到了这个Android问题跟踪器
为了解释我的问题,我做了一个示例App.
我的示例应用程序的基本工作
我想要实现的目标
我是如何实现这一目标的
wasEditing = true.wasEditing = true.wasEditing,如果是,我请求焦点为EditText.imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)我遇到问题的地方
有时在执行此调用后,键盘在少数情况下不可见,例如在方向更改期间.
当我把日志我发现这个函数返回false
但是,如果我有这样的showSoftInput()电话使用100毫秒的延迟一些mEditText.postDelayed()在onResume()一切工作正常.
问题 在什么情况下此函数返回false并且为什么延迟有效?
注意 虽然我已经使用延迟解决了我的问题,但我仍然想知道为什么它表现得那样.
我有一个包含两个活动的应用程序,有时,我需要切换活动,同时在刚刚恢复的活动的操作栏中打开搜索输入。一切正常,只是我无法让键盘出现。我的代码的相关部分如下(注意:true如果需要搜索输入,则布尔值 startsearch 设置为切换活动的结果):
public class MyActivity extends Activity {
private InputMethodManager imm;
public boolean startsearch;
private MenuItem DestinationTxt;
private SearchView mySearchView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// various initialisation, and then:
startsearch = false;
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
DestinationTxt = menu.findItem(R.id.actionbar_search);
mySearchView = (SearchView)DestinationTxt.getActionView();
// more menu create stuff appears here
}
@Override
public void onResume() {
super.onResume();
if (startsearch) {
DestinationTxt.expandActionView();
imm.showSoftInput(mySearchView, …Run Code Online (Sandbox Code Playgroud) 嗨我将edittext控件包装到用户请求屏幕上显示的控件上.它覆盖整个屏幕,直到用户按下键盘上的"完成"按钮.
我无法在屏幕上明确显示控件.只有当用户点击控制权时才会显示.我错过了什么吗?
我甚至尝试了这个,当我启动编辑文本存在的叠加层时,它并没有使用它:
customCOntrol.showKeyboard();
public void showKeyboard()
{
InputMethodManager imm = (InputMethodManager)_context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this._textView.getWindowToken(), InputMethodManager.SHOW_IMPLICIT);
}
Run Code Online (Sandbox Code Playgroud)
这是我在配置文件android屏幕上的settig:windowSoftInputMode ="stateHidden | adjustPan"
先感谢您