我目前正在使用以下代码显示软键盘
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, InputMethodManager.RESULT_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
在这里我没有用Edittext绑定软键盘,因为我使用了上面的代码.
现在我想关闭SoftKeyboard,所以我目前正在使用下面的代码,但它无法正常工作.
imm.toggleSoftInput (InputMethodManager.SHOW_FORCED, InputMethodManager.RESULT_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我使用什么来关闭softKeyboard?
基于下面的答案,我想让你清楚我没有使用EditText,我使用Layout来显示键盘和隐藏键盘.我想将键盘键事件发送到我没有使用editText的远程区域bcoz.
我正在开发一个键盘应用程序,但我正在解决一个问题.我想以编程方式在android中的EditText中限制/阻止软键盘中的某些特殊字符.
那么,有没有什么办法可以限制android中编辑文本中的任何特殊字符输入.
如果有人有想法,请回复.
提前致谢.
我在我的应用程序中使用recylerview,每当将新元素添加到recyclerview时,它就会使用滚动到最后一个元素
recyclerView.scrollToPosition(adapter.getCount());
Run Code Online (Sandbox Code Playgroud)
但是,每当键盘打开时(因为editTextView),它会调整视图大小并且recyclerview变小,但无法滚动到最后一个元素.
android:windowSoftInputMode="adjustResize"
Run Code Online (Sandbox Code Playgroud)
我甚至尝试使用以下代码滚动到最后一个元素,但它不起作用
editTextView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
recyclerView.scrollToPosition(chatAdapter.getItemCount());
}
}
});
Run Code Online (Sandbox Code Playgroud)
我可以尝试adjustPan将平移向上移动,但它隐藏了我的工具栏.请提出任何解决问题的方法.
我有一个带有一些EditText字段和一些按钮的Activity,以方便通常用于填充这些字段的内容.但是,当我们用户触摸其中一个EditText字段时,会自动显示Android软键盘.我希望它默认保持隐藏状态,除非用户长按菜单按钮.我已经找到了解决方案,并找到了几个答案,但到目前为止我无法让它们工作.
我尝试过以下方法:
1 - 在onCreate方法中,
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
2 - 同样在onCreate方法中,
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
Run Code Online (Sandbox Code Playgroud)
3 - 和fIn清单文件,
<activity android:name=".activityName" android:windowSoftInputMode="stateAlwaysHidden"/>
Run Code Online (Sandbox Code Playgroud)
这些方法都不起作用.只要用户单击EditText字段,就会出现软键盘.如果用户通过长按菜单键明确显示软键盘,我只想显示软键盘.
为什么这不起作用?
我有一个"保存"按钮,我想用软键盘一起推.因此,当用户单击布局中的EditText时,该按钮必须保持在键盘上方.现在按钮隐藏在键盘下方.你怎么做到这一点?
提前致谢!
在我的Android应用程序中我有一个聊天活动,我使用android-chat-starter中的代码
问题是在模拟器中一切正常,我在许多类型的模拟器中测试它(api> 18,api = 18,api <18)但是在实际设备中测试它的行为就像在这个图像中
表情符号视图显示在键盘上方
这是我用来显示表情符号视图的代码
private void showEmojiPopup(boolean show) {
showingEmoji = show;
if (show) {
if (emojiView == null) {
if (getActivity() == null) {
return;
}
emojiView = new EmojiView(getActivity());
emojiView.setListener(new EmojiView.Listener() {
public void onBackspace() {
chatEditText1.dispatchKeyEvent(new KeyEvent(0, 67));
}
public void onEmojiSelected(String symbol) {
int i = chatEditText1.getSelectionEnd();
if (i < 0) {
i = 0;
}
try {
CharSequence localCharSequence = Emoji.replaceEmoji(symbol, chatEditText1.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20));
chatEditText1.setText(chatEditText1.getText().insert(i, localCharSequence));
int j = i …Run Code Online (Sandbox Code Playgroud) 是否可以捕获为EditText显示或隐藏软键盘的事件?
我正在尝试创建一个非常基本的聊天屏幕,其中ListView显示文本,底部是EditText,EditText右侧是"发送"按钮.一切都很实用,但当我点击EditText时,虚拟键盘会覆盖它.屏幕平移一点但不足以在键盘上方可见.我的清单中有"adjustPan"标签,并且还尝试了"adjustResize"标签无效.我猜这与我的布局设置方式有关,但老实说我没有任何线索.请帮忙!
当前布局......
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@+id/android:list"
android:layout_height="0dip"
android:layout_width="fill_parent"
android:layout_weight="1"
android:stackFromBottom="true">
</ListView>
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/sendMessageBox"
android:focusable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:scrollbars="vertical"
android:maxLines="4"
android:text=""
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:maxLength="1000"
android:hint="Type your message..."
android:imeOptions="actionSend"/>
<Button android:id="@+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="Send"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
android android-manifest android-layout android-softkeyboard
我已经关注了developer.android.com上有关 输入法的示例,并使用了SoftKeyboard示例应用程序.这些共同提供了有关简单键盘创建的足够信息.
我在API中看不到的是能够在标准键盘(LatinIME键盘)上为每个键创建备用/多个字符.

上面的图像是长按"a"键的结果.当您长按一个键时,可以使用替换字符填充弹出窗口.

也可以在某些键上给出一个弹出提示,提示用户按住一个键以获得弹出菜单.
到目前为止,我还没有找到关于如何实现这一目标的单一信息来源,希望有人能够给我一个良好的开端,直到那时我将遵循内置键盘的源代码,看看我是否可以进行逆向工程它.
编辑:如果developer.android.com的LatinIME键盘链接没有链接到一个羊的图片会有帮助:) LatinIME.java的实际源代码.
编辑2:更多作为参考而不是其他任何东西,这是我认为通常的longPress操作通过以便在KeyboardView.java中显示弹出键盘的序列:
onTouchEvent()
onModifiedTouchEvent()
mHandkler.handleMessage() with MSG_LONGPRESS
openPopupIfRequired()
onLongPress()
Run Code Online (Sandbox Code Playgroud)
编辑3:
我仍然没有想到这一点 - 如何向键添加标签建议?答案表明它没有内置到API中,事实上我还没有找到代码来执行此操作.但是,2.3.4(API 10)上的键盘显示正在实现此功能:

非常想弄清楚IT是如何做到的,但它不是onDraw()我能看到的方法中的任何地方- 这让我相信它是在KeyboardView元素之外编写的.然而,我无法找到layout用于在内置键盘上显示KeyboardView元素的文件 - 如果有人知道在哪里找到这个也许会给我提供我需要的线索.
编辑4:移动键预览问题,因为它稍微偏离主题:
我希望FAB浮在键盘上.而已.
例如
Blank Activity使用Android Studio 打开一个新模板项目TextView为EditText