我的布局中有一个EditText和一个Button.
在编辑字段中写入并单击后Button,我想隐藏虚拟键盘.我假设这是一段简单的代码,但我在哪里可以找到它的一个例子?
android soft-keyboard android-layout android-softkeyboard android-input-method
我需要做一个非常简单的事情 - 找出是否显示了软件键盘.这在Android中可行吗?
我想在EditText聚焦时自动显示软键盘(如果设备没有物理键盘),我有两个问题:
当我Activity显示时,我EditText的注意力集中但键盘没有显示,我需要再次点击它来显示键盘(显示我的键盘时应Activity显示).
当我在键盘上单击完成时,键盘被解除但是EditText保持聚焦并且不想要(因为我的编辑完成了).
要恢复,我的问题是在iPhone上有更多类似的东西:它使键盘与我的EditText状态同步(聚焦/不聚焦),当然如果有物理键盘,则不会出现软键盘.
keyboard android focus android-softkeyboard android-edittext
我无法弄清楚这一点.有些应用程序有一个EditText(文本框),当你触摸它并调出屏幕键盘时,键盘上有一个"搜索"按钮而不是一个回车键.
我想实现这个.如何实现"搜索"按钮并检测按"搜索"按钮?
编辑:找到如何实现搜索按钮; 用XML android:imeOptions="actionSearch"或Java EditTextSample.setImeOptions(EditorInfo.IME_ACTION_SEARCH);.但是如何处理用户按下"搜索"按钮?它与之有关android:imeActionId吗?
好的,大家都知道要隐藏你需要实现的键盘:
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
但这里最重要的是当用户触摸或选择任何其他不是EditText软键盘或软键盘的地方时如何隐藏键盘?
我试图onTouchEvent()在我的父母Activity身上使用,但这只有在用户触摸任何其他视图以外且没有滚动视图时才有效.
我尝试实现触摸,单击,集中监听器而没有任何成功.
我甚至尝试实现自己的scrollview来拦截触摸事件,但我只能获取事件的坐标而不是点击的视图.
有没有一种标准的方法来做到这一点?在iPhone中它真的很容易.
在使用软键盘的Android设备上,我希望防止在横向模式下出现全屏键盘编辑视图(如下所示)(即我只想看到软键盘本身和我后面的视图).
我假设这可以使用setExtractViewShown(false)方法on 来实现InputMethodService,但我无法访问此默认实例并且不想实现自定义输入方法.

编辑添加:输入的视图不是TextView(它是View一个自定义InputConnection实现),所以android:imeOptions="flagNoExtractUi"在这里不起作用.
我想根据是否显示虚拟键盘来改变布局.我搜索过API和各种博客,但似乎找不到任何有用的东西.
可能吗?
谢谢!
当软键盘处于活动状态并且我已成功实现它时,我已经研究了很多调整布局但是当我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"在清单文件中的活动标签中使用它时问题就出现了.
为此,我使用android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"了不同的选项,但没有运气.
之后,我以FullScreen编程方式实现并尝试了各种布局,FullScreen但都是徒劳的.
我引用了这些链接,并在此处查看了许多与此问题相关的帖子:
http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
http://davidwparker.com/2011/08/30/android-how-to-float-a-row-above-keyboard/
这是xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/masterContainerView"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffffff">
<ScrollView android:id="@+id/parentScrollView"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<TextView android:id="@+id/setup_txt" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Setup - Step 1 of 3"
android:textColor="@color/top_header_txt_color" android:textSize="20dp"
android:padding="8dp" android:gravity="center_horizontal" />
<TextView android:id="@+id/txt_header" android:layout_width="fill_parent"
android:layout_height="40dp" android:text="AutoReply:"
android:textColor="@color/top_header_txt_color" android:textSize="14dp"
android:textStyle="bold" android:padding="10dp"
android:layout_below="@+id/setup_txt" />
<EditText android:id="@+id/edit_message"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Some text here." android:textSize="16dp"
android:textColor="@color/setting_editmsg_color" android:padding="10dp"
android:minLines="5" android:maxLines="6" android:layout_below="@+id/txt_header"
android:gravity="top" android:scrollbars="vertical"
android:maxLength="132" />
<ImageView android:id="@+id/image_bottom"
android:layout_width="fill_parent" android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我正在尝试在使用NumberPicker输入数值时停用软键盘(出于美观原因).这是我的layout-xml代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="30dp"
android:layout_marginTop="30dp" >
<NumberPicker
android:id="@+id/repetitionPicker"
android:layout_width="40dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/repetitions_short_divider"
android:textAppearance="?android:attr/textAppearanceMedium" />
<NumberPicker
android:id="@+id/weightPicker"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/pounds"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<Button
android:id="@+id/saveButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/save" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
最后这是我尝试在onCreate() - 方法中阻止键盘的代码:
// hide keyboard
View.OnClickListener disableKeyBoardListener = new View.OnClickListener() {
public void onClick(View v) {
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
};
((EditText) weightPicker.getChildAt(1)).setInputType(InputType.TYPE_NULL);
((EditText) …Run Code Online (Sandbox Code Playgroud) android android-widget android-layout android-softkeyboard android-edittext
我想在软键盘激活时调整/重新调整布局大小,如下所示:
之前和之后:


在SO中找到了几个资源:
但问题和答案相当模糊,这里的问题是我想要的更清晰的画面.
要求: