我想将斯堪的纳维亚键盘设置为 android 设备上的默认键盘,我想通过代码来做到这一点。所以我尝试使用 InputMethodManager :
InputMethodManager mng = (InputMethodManager)getSystemService(LoginActivity.INPUT_METHOD_SERVICE);
List<InputMethodInfo> m_list=mng.getInputMethodList();
Run Code Online (Sandbox Code Playgroud)
我找到了 InputMethodManager 类的方法 setInputMethod (IBinder token, String id)。但是我没有找到解释我如何使用它的示例/文档。有什么建议吗?谢谢。
我正在尝试使用该键盘输入的命令关闭名为 onboard 的 Ubuntu 屏幕键盘。如果我使用屏幕键盘本身键入如下终止命令,会发生什么情况。. .
killall onboard
Run Code Online (Sandbox Code Playgroud)
然后在屏幕键盘上再次按下 Enter,我在我所在的终端上连续按下 Enter。这就像我拔掉了一个物理键盘,它一直认为我正在按下我在拔掉插头时按下的键。
我在网上找不到任何关于如何更好地做到这一点的文档,所以我想我会在这里问。我尝试了以下发送以下所有具有相同行为的终止信号:1 (SIGHUP)、2 (SIGINT)、9 (SIGKILL)、15 (SIGTERM) 和 24 (SIGXCPU)。
有任何想法吗?我希望我遗漏了一些明显的东西。. .
我尝试了以下代码,但由于某种原因,每当我按下键盘上的 Enter 键时,键盘都不会退出。为什么这不起作用?
func trynaReturnKeyboard -> Bool {
firstTextField.resignFirstResponder()
secondTextField.resignFirstResponder()
return true
}
Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要在浏览器中显示的 Web 表单上单击鼠标,还需要进行一些键盘输入,如用数字填充文本框或按向下箭头顺序排列,以便在组合框中进行选择。
我拥有的窗口处理程序,点击的坐标,它对我来说很好用(非常简单的功能):
extern "C" __declspec(dllexport) void __stdcall PutSingleClick(unsigned hwnd, int x, int y)
{
SendMessage(((HWND) hwnd), WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(x, y));
SendMessage(((HWND) hwnd), WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(x, y));
}
Run Code Online (Sandbox Code Playgroud)
当我尝试发送键盘输入时出现我的问题,例如通过调用:
extern "C" __declspec(dllexport) void __stdcall PutKeystrokeDown(int times)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.wVk = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wScan = VK_DOWN;
for(int i = 0; i < times; i++)
{
ip.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
}
ip.ki.dwFlags …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个自定义渲染器,它允许我将'SearchBar'的键盘类型更改为Numeric.
这是我的渲染器:
[assembly: ExportRenderer(typeof(CustomSearchBar), typeof(SearchBarRenderer))]
namespace App.Droid.CustomRenderers
{
class CustomSearchBarRenderer : SearchBarRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
{
base.OnElementChanged(e);
var customSearchBar = (CustomSearchBar)Element;
customSearchBar.keyboard = Keyboard.Numeric;
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后是自定义控件:
public class CustomSearchBar : SearchBar
{
public Keyboard keyboard { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以及自定义控件的用法:
var _mySearchBar = new CustomSearchBar();
Run Code Online (Sandbox Code Playgroud)
我虽然有点偏僻.该OnElementChanged事件永远不会被命中,但即使它只是将自定义键盘属性设置为数字,而不是设置显示键盘的实际KeyboardType.不知道从哪里开始.任何帮助,将不胜感激.
我发现这个关于使用jQuery 绑定箭头键的优秀问题:JS/jQuery中的绑定箭头键与Sygmoral的一个很好的解决方案:
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
break;
case 38: // up
break;
case 39: // right
break;
case 40: // down
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
Run Code Online (Sandbox Code Playgroud)
除了:这可以防止箭头键以焦点位于文本输入字段中时通常的方式工作.
当当前焦点位于输入,文本区域或其他内容可编辑区域时,如何修改此解决方案以允许箭头键正常工作?
我遇到了一个editText的情况.当我在编辑文本中按添加时,我在列表中添加成员.何时添加(或不添加)我正在打开自定义对话框.
在我的活动中,当点击编辑文本中的添加按钮时,我有这个代码:
customDialogTeamMember = new CustomDialogTeamMember(............);
customDialogTeamMember.makeDialog();
editText.getText().clear();
editText.clearFocus();
hideSoftKeyboard();
Run Code Online (Sandbox Code Playgroud)
我的hideSoftKeyboard()定义如下:
public void hideSoftKeyboard() {
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
Run Code Online (Sandbox Code Playgroud)
此方法适用于应用程序的其他部分.但这里没有用!
自定义对话框打开.当我关闭它时,键盘保持在屏幕上.可能是什么问题呢?!
//code of AlertDialog
final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setTitle(R.string.modification);
persoFomulair=new ListView(getActivity());
List<HashMap<Boolean,HashMap<String,String>>>list = prepareList(p);
MyListAdapter2 myListAdapter2 = new MyListAdapter2(getActivity(), R.layout.perso_list, list);
persoFomulair.setAdapter(myListAdapter2);
alert.setView(persoFomulair);
alert.setPositiveButton(R.string.valider, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//What ever you want to do with the value
getValueOfItem();
ModifierPerso modifierPerso = new ModifierPerso();
modifierPerso.execute(type, String.valueOf(p.getId()), date_embauch, salair_journ);
}
});
alert.setNegativeButton(R.string.annuler, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
});
AlertDialog …Run Code Online (Sandbox Code Playgroud)keyboard android listview android-edittext android-alertdialog
我查看并尝试了Swift 3,Xcode 8的多个解决方案,但无法使用.我试过了:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
Run Code Online (Sandbox Code Playgroud)
并将文本字段输入设置为第一响应者:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
pressureInput.resignFirstResponder()
}
Run Code Online (Sandbox Code Playgroud)
我不知道从Xcode 8到Xcode 9的某些东西导致这些方法不起作用,或者我是否在其他地方搞砸了.我有9个文本字段,他们都设置了委托给自己.它们的标签会增加,以便在按下返回时移动到下一个文本字段.不要以为这会影响它.对不起,新来的!这些尝试函数中的任何一个都可以正常运行代码,但键盘保持不变.我想在任何文本字段之外触摸时解除键盘.
在离子模式中,当某些东西不在离子含量范围内并打开键盘时,当屏幕上的键盘关闭时,会在键盘出现的地方显示空白。