如何确定当前处于活动状态的输入法 - 用户可以通过长按文本编辑字段来更改输入法(软键盘) - 从代码中,如何确定用户选择的输入法
我写了一个IME(InputMethodService),我需要从它正在编辑的EditText中获取所有文本.我知道一种方式:
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.append(inputConnection.getTextBeforeCursor(9999, 0))
.append(inputConnection.getTextAfterCursor(9999, 0));
Run Code Online (Sandbox Code Playgroud)
它有效,但看起来非常愚蠢和笨重.然而,没有这样的方法InputConnection.getText().
有没有更好的办法?
PS我无法从我的IME访问EditText,因为它属于父app,所以请不要告诉我使用EditText.getText(),除非你知道一种获取EditText的方法!
我的应用程序打开输入法选择器(您选择键盘的菜单)InputMethodManager.showInputMethodPicker().我的应用程序实际上并没有创建选择器(它是由InputMethodManager创建的),但我知道它是a ContextMenu并且它的id是R.id.switchInputMethod.

选择器是多步骤向导的一部分,因此我需要知道选择器何时关闭,以便我的应用程序可以继续执行下一步.现在我正在检查后台线程中是否更改了默认键盘,但如果用户选择相同的键盘或按下则无效.
所以我需要一种方法来判断选择器何时关闭(或者其他一些聪明的方式来知道何时继续).
提前致谢...
嗨,我需要一个软键盘只用数值0来9和Enter关键.不应该显示除了这些之外的任何东西. , ( )......

setRawInputType(Configuration.KEYBOARD_QWERTY)setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)setRawInputType(InputType.TYPE_CLASS_NUMBER)setRawInputType(InputType.TYPE_CLASS_PHONE)我总是在键盘上显示额外的字符,如:

setRawInputType(Configuration.KEYBOARD_12KEY) 显示这样的键盘:

非常感谢任何帮助.提前致谢.
注意:
android:minSdkVersion="14":ICS4.0android:targetSdkVersion="17":JB 4.2qwerty android ime android-softkeyboard android-input-method
我有一个状态列表drawable,我想从状态列表drawable得到一个特定的drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:kplus="http://schemas.android.com/apk/res-auto">
<item kplus:key_type_space_alt="true" android:state_pressed="true" android:drawable="@drawable/space_1_pressed" />
<item kplus:key_type_space_alt="true" android:drawable="@drawable/space_1_normal" />
<!-- TopNav keys. -->
<item kplus:key_type_topnav="true" android:state_pressed="true" android:drawable="@drawable/tab_down" />
<item kplus:key_type_topnav="true" android:state_selected="true" android:drawable="@drawable/tab_down" />
<item kplus:key_type_topnav="true" android:drawable="@drawable/tab_normal" />
<!-- TopRow keys. -->
<item kplus:key_type_toprow="true" android:state_pressed="true" android:drawable="@drawable/numeric_presseed" />
<item kplus:key_type_toprow="true" android:drawable="@drawable/numeric_normal" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我为每个键选择了正确的可绘制状态,如下所示:
if (keyIsNumbers) {
if (KPlusInputMethodService.sNumbersState == 2) {
drawableState = mDrawableStatesProvider.KEY_STATE_TOPNAV_CHECKED;
}
}
Run Code Online (Sandbox Code Playgroud)
现在状态定义如下:
KEY_STATE_TOPNAV_NORMAL = new int[] {keyTypeTopNavAttrId};
KEY_STATE_TOPNAV_PRESSED = new int[] {keyTypeTopNavAttrId, android.R.attr.state_pressed};
KEY_STATE_TOPNAV_CHECKED = new int[] {keyTypeTopNavAttrId, android.R.attr.state_selected}; …Run Code Online (Sandbox Code Playgroud) android android-layout android-input-method statelistdrawable android-drawable
我正在为Android构建一个自定义软键盘,并希望添加一个布局,以包括类似于默认Android键盘(AOSP)正在做的表情符号键.我一直在搜索,但似乎大多数人都试图从图像中显示自定义表情符号.我想展示Android附带的内置图标(如下所示):

似乎我应该能够使用Unicode字符从键盘发送图像,但我的第一次尝试似乎只生成了emojis的旧版本.我如何支持手机可以处理的最新表情符号?另外,如何在键盘上显示表情符号,如上图所示?
android emoticons android-softkeyboard emoji android-input-method
我在Activity中的Fragment中有一个EditText.
我的活动布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_bg">
...
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中的我的Activity配置:
<activity
android:name="com.demo.LoginActivity"
android:configChanges="orientation|keyboardHidden"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/activityTheme" />
Run Code Online (Sandbox Code Playgroud)
用于在Activity中启动片段的代码:
private void startFragment(BaseFragment fragment, String tag) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.commitAllowingStateLoss();
}
Run Code Online (Sandbox Code Playgroud)
我的片段布局:
<?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:background="@color/common_background_color_white"
android:orientation="vertical"
android:clickable="true"
android:paddingLeft="@dimen/email_common_padding_horizontal"
android:paddingRight="@dimen/email_common_padding_horizontal">
...
<com.example.widget.LineEditView
android:id="@+id/login_email_input"
style="@style/BaseEditText.LoginEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
/>
...
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我的自定义窗口小部件LineEditView是子类扩展RelativeLayout,它的布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/input" …Run Code Online (Sandbox Code Playgroud) keyboard android android-softkeyboard android-input-method android-fragments
为android编写字典应用程序.想要根据当前输入语言设置翻译方向(更准确地说,软键盘上显示的字母语言).例如,我们得到了英语 - 法语的语言对.我想要的是,当用户输入英文字母(显示英文键盘布局)时,翻译方向是直的,当键盘布局改为法语时,翻译方向也会改变为倒置.
所以,问题是:在Android输入法框架中是否有任何事件,它允许跟踪这种布局的变化.如果没有,也许有一些标准的技巧来做我需要的?
先谢谢你,Alex
android keyboard-layout keyboard-events android-input-method
最近在开发应用程序时,我遇到了一个问题.我在谷歌搜索了很多,但找不到任何解决方案.最后,我遇到了这个Android问题跟踪器
为了解释我的问题,我做了一个示例App.
我的示例应用程序的基本工作
我想要实现的目标
我是如何实现这一目标的
wasEditing = true.wasEditing = true.wasEditing,如果是,我请求焦点为EditText.imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)我遇到问题的地方
有时在执行此调用后,键盘在少数情况下不可见,例如在方向更改期间.
当我把日志我发现这个函数返回false
但是,如果我有这样的showSoftInput()电话使用100毫秒的延迟一些mEditText.postDelayed()在onResume()一切工作正常.
问题 在什么情况下此函数返回false并且为什么延迟有效?
注意 虽然我已经使用延迟解决了我的问题,但我仍然想知道为什么它表现得那样.
我的布局中有一个EditText和一个Button.在编辑字段中写入并单击此按钮后 go back my fragment,我想隐藏虚拟键盘.我认为有一个简单的,但我尝试了某种方式,它不起作用:
该代码显示了如何Button工作:
private void onButtonClicked(){
getActivity().getSupportFragmentManager().popBackStack();
}
Run Code Online (Sandbox Code Playgroud)
某些解决方案的代码,但这无济于事.这个代码我用,hideSoftInputFromWindow但是当我调用'EditText.getWindowToken()'时,它不会隐藏软键盘(我也将0值更改为InputMethodManager.HIDE_IMPLICIT_ONLY或InputMethodManager.HIDE_NOT_ALWAYS并且它不起作用):
EditText myEditText = (EditText) findViewById(R.id.myEditText);
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)
使用此代码,在此应用程序的另一个屏幕中,它可以工作.这个屏幕是一个活动所以我认为问题是片段的问题.
我的片段代码:
public class ChangeEmailFragment extends BaseFragment {
private TextView mTxtCurrentEmail;
private EditText mEdtNewEmail;
private EditText mEdtPassword;
private TextView mTxtSubmit;
@Override
public void onStop() {
super.onStop();
if (progressDialog != null && progressDialog.isShowing())
progressDialog.dismiss();
if (dialog != null && dialog.isShowing())
dialog.dismiss();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup …Run Code Online (Sandbox Code Playgroud)