我有一个AlertDialog大约有10个控件(文本和TextView)的盒子.这些控件是在ScrollView与AlertDialog,再加上我有2个按钮正面和负面的.我遇到的问题是当弹出软键盘时,两个按钮隐藏在键盘后面.
我在内部视图或对话框中寻找重绘功能.下面是我正在谈论的屏幕截图.

android resize view android-softkeyboard android-alertdialog
我在SO上搜索了六个其他答案,但没有找到一个有效的答案.我只想在用户按下回车键时关闭软键盘.(相当于疯狂的iOS'resignKeyboard'调用.)在下面的代码中,不会调用onEditorAction方法.我在我的XML文件中设置了EditText视图,片段中的代码如下:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
fragView = inflater.inflate(R.layout.fragment_encrypt2, container, false);
textField = (EditText) fragView.findViewById(R.id.textField);
textField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView arg0, int actionId,
KeyEvent arg2) {
// hide the keyboard and search the web when the enter key
// button is pressed
if (actionId == EditorInfo.IME_ACTION_GO
|| actionId == EditorInfo.IME_ACTION_DONE
|| actionId == EditorInfo.IME_ACTION_NEXT
|| actionId == EditorInfo.IME_ACTION_SEND
|| actionId == EditorInfo.IME_ACTION_SEARCH
|| (arg2.getAction() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textField.getWindowToken(), …Run Code Online (Sandbox Code Playgroud) android actionlistener android-softkeyboard android-input-method
我有一个包含编辑文本的片段.按下编辑文本时,将显示键盘.按下上角的"保存"按钮时,应用程序将返回上一个片段,但键盘仍然存在.
我希望在导航到上一个片段时隐藏键盘.
请注意,我尝试了这个解决方案: 关闭/隐藏Android软键盘.
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myView.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
我尝试在onCreate方法的两个片段中使用它.
我还尝试在布局中隐藏软键盘:
android:windowSoftInputMode="stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)
不幸的是,这些都没有奏效.
我会张贴一些照片,但我还没有足够的名声.我会感激任何建设性的帮助和意见,不要忘记"聪明的人可以从愚蠢的问题中学到更多,而不是傻瓜可以从明智的答案中学习." :)
此致,亚历山德拉
我尝试使用input.setImeOptions(EditorInfo.IME_ACTION_DONE)在软键盘上设置"完成"按钮;
但"完成"按钮根本不会显示在软键盘上.
有什么建议吗?
public void modif(int position) {
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert.setTitle("Modifica");
EditText input = new EditText(MainActivity.this);
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
alert.setView(input);
final Editable value = input.getText();
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(getApplicationContext(), value, Toast.LENGTH_LONG).show();
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
}
Run Code Online (Sandbox Code Playgroud) 是否可以隐藏特定的键盘按钮?我有一个EditText和一些设备上它的键盘有笑脸,而在其他设备上它缺少.我想在所有设备上隐藏它.
以下是我的XML EditText:
android:id="@+id/text_editor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/send_side"
android:hint="Enter your text"
android:imeOptions="actionSend|flagNoEnterAction"
android:inputType="textLongMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:maxLength="1000"
android:maxLines="3"
android:nextFocusRight="@+id/send_button"
android:padding="12dp"
android:textSize="13sp"
Run Code Online (Sandbox Code Playgroud)
我不得不说我是Android新手,如果不可能,我想知道原因.
谢谢您的帮助.
根据材料设计规范,当键盘出现时,BottomNavigationView应该隐藏在它下面.但是,如果我android:windowSoftInputMode="adjustResize"在Activity的清单中设置BottomNavigationView了键盘上方的移动.
我需要设置adjustResize为在键盘打开时滚动到屏幕底部.但是,我不希望它BottomNavigationView是可见的.可以这样做吗?
它目前的样子:
布局XML(实际上会有一个FrameLayout在哪里,EditText并且EditText将在其中):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Input"
android:layout_gravity="center"
android:layout_centerVertical="true"/>
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:menu="@menu/menu_bottom_navigation"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 当用户点击Edittext以外的任何地方时,我需要在android中隐藏softkeypad.iphone有很多帮助,但不适用于android.我试过这段代码,但它无法正常工作:(
final RelativeLayout base = (RelativeLayout) findViewById(R.id.RelativeLayout1);
findViewById(R.id.base).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(base.getWindowToken(), 0);
}
});
Run Code Online (Sandbox Code Playgroud)
提前致谢 !
当我的用户按下Enter虚拟机器人"用户验证条目!"时 键盘我的键盘保持可见!(为什么?)
这是我的Java代码......
private void initTextField() {
entryUser = (EditText) findViewById(R.id.studentEntrySalary);
entryUser.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
userValidateEntry();
return true;
}
}
return true;
}
});
}
private void userValidateEntry() {
System.out.println("user validate entry!");
}
Run Code Online (Sandbox Code Playgroud)
......在这里我的观点
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content">
<EditText android:id="@+id/studentEntrySalary" android:text="Foo" android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的虚拟设备上可能有问题?
我正在开发使用Android 2.2的平板电脑.
我有一个表单,我用于新的和可编辑的实例.可编辑时,我想阻止用户编辑某些字段.我在我的onStart-event中设置了这个,设置了txt.setFocusableInTouchMode(false).这会强制焦点转到下一个可聚焦EditText的形式(这很棒),但在运行时,软键盘会自动显示EditText焦点.谁知道如何制止这个?
这是代码(在onStart事件中调用):
private void PopulateFields(){
TextView txtTitle = (TextView) this.findViewById(R.id.txtEquipmentEditTitle);
AutoCompleteTextView txtMake = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditMake);
AutoCompleteTextView txtModel = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditModel);
EditText txtDesc = (EditText) this.findViewById(R.id.txtEquipmentEditDesc);
TextView txtDeptKey = (TextView) this.findViewById(R.id.txtEquipmentEditDeptKey);
EditText txtSerial = (EditText) this.findViewById(R.id.txtEquipmentEditSerialNo);
EditText txtBarCode = (EditText) this.findViewById(R.id.txtEquipmentEditBarCode);
txtTitle.setText("Edit Equipment");
txtMake.setText(make);
txtModel.setText(model);
txtDesc.setText(desc);
txtDeptKey.setText(Integer.toString(deptKey));
txtSerial.setText(serial);
txtBarCode.setText(barCode);
txtMake.setEnabled(false);
txtModel.setEnabled(false);
txtDesc.setEnabled(false);
txtMake.setClickable(false);
txtMake.setFocusableInTouchMode(false);
txtModel.setFocusableInTouchMode(false);
txtDesc.setFocusableInTouchMode(false);
txtMake.setFocusable(false);
txtModel.setFocusable(false);
txtDesc.setFocusable(false);
}
Run Code Online (Sandbox Code Playgroud) 当软键盘弹出时,如何创建一个不会随视图移动的粘性页脚?
下面是我当前设置的图像示例以及我想要实现的目标.我有一个包含我的页面内容的scrollview和一个与作为导航栏的父底部对齐的linearlayout.
问题是当键盘弹出时,它会推动我的整个视图,包括底部导航部分.我不想禁用视图的自动上推(通过设置android:windowSoftInputMode="adjustPan"),而是排除单个元素被推上,我的底部导航栏.
我测试了windowSoftInputMode修复,但它隐藏了键盘后面的页面内容.有没有办法让它继续推高滚动视图而不是底部导航?我的另一个选择是设置visibility:gone键盘,然后在键盘上重新显示它,但这看起来过于复杂,并不总是可靠的我阅读.
如果有人有任何例子或建议,我会全力以赴.谢谢.