标签: android-input-method

Android:从代码确定活动输入法

如何确定当前处于活动状态的输入法 - 用户可以通过长按文本编辑字段来更改输入法(软键盘) - 从代码中,如何确定用户选择的输入法

android android-input-method

11
推荐指数
1
解决办法
8654
查看次数

从InputConnection获取EditText中的所有文本的更好方法是什么?

我写了一个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的方法!

android android-input-method android-edittext

11
推荐指数
2
解决办法
4257
查看次数

如何判断输入法选择器是打开还是关闭?

我的应用程序打开输入法选择器(您选择键盘的菜单)InputMethodManager.showInputMethodPicker().我的应用程序实际上并没有创建选择器(它是由InputMethodManager创建的),但我知道它是a ContextMenu并且它的id是R.id.switchInputMethod.

在此输入图像描述

选择器是多步骤向导的一部分,因此我需要知道选择器何时关闭,以便我的应用程序可以继续执行下一步.现在我正在检查后台线程中是否更改了默认键盘,但如果用户选择相同的键盘或按下则无效.

所以我需要一种方法来判断选择器何时关闭(或者其他一些聪明的方式来知道何时继续).

提前致谢...

android android-input-method android-contextmenu

11
推荐指数
2
解决办法
3300
查看次数

需要数量只有软键盘?

嗨,我需要一个软键盘只用数值09Enter关键.不应该显示除了这些之外的任何东西. , ( )......

在此输入图像描述

我尝试了这里建议的几个选项,但没有什么似乎对我有用.

  1. setRawInputType(Configuration.KEYBOARD_QWERTY)
  2. setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED)
  3. setRawInputType(InputType.TYPE_CLASS_NUMBER)
  4. setRawInputType(InputType.TYPE_CLASS_PHONE)

我总是在键盘上显示额外的字符,如:

在此输入图像描述

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

在此输入图像描述

非常感谢任何帮助.提前致谢.

注意:

  • android:minSdkVersion="14":ICS4.0
  • android:targetSdkVersion="17":JB 4.2

qwerty android ime android-softkeyboard android-input-method

11
推荐指数
1
解决办法
1万
查看次数

从状态列表drawable获取特定的drawable

我有一个状态列表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

10
推荐指数
1
解决办法
6145
查看次数

显示用于inputmethod的内置表情符号键

我正在为Android构建一个自定义软键盘,并希望添加一个布局,以包括类似于默认Android键盘(AOSP)正在做的表情符号键.我一直在搜索,但似乎大多数人都试图从图像中显示自定义表情符号.我想展示Android附带的内置图标(如下所示):

Android内置表情符号

似乎我应该能够使用Unicode字符从键盘发送图像,但我的第一次尝试似乎只生成了emojis的旧版本.我如何支持手机可以处理的最新表情符号?另外,如何在键盘上显示表情符号,如上图所示?

android emoticons android-softkeyboard emoji android-input-method

10
推荐指数
2
解决办法
1694
查看次数

如何在Android中的片段中完美展示软键盘?

我在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

9
推荐指数
2
解决办法
1万
查看次数

Android键盘布局语言

为android编写字典应用程序.想要根据当前输入语言设置翻译方向(更准确地说,软键盘上显示的字母语言).例如,我们得到了英语 - 法语的语言对.我想要的是,当用户输入英文字母(显示英文键盘布局)时,翻译方向是直的,当键盘布局改为法语时,翻译方向也会改变为倒置.

所以,问题是:在Android输入法框架中是否有任何事件,它允许跟踪这种布局的变化.如果没有,也许有一些标准的技巧来做我需要的?

先谢谢你,Alex

android keyboard-layout keyboard-events android-input-method

8
推荐指数
1
解决办法
1055
查看次数

为什么android InputMethodManager.showSoftInput()返回false?

最近在开发应用程序时,我遇到了一个问题.我在谷歌搜索了很多,但找不到任何解决方案.最后,我遇到了这个Android问题跟踪器

为了解释我的问题,我做了一个示例App.

我的示例应用程序的基本工作

  1. 我有一个屏幕,它有一个EditText,一个Button和一个RelativeLayout.
  2. RelativeLayout的宽度和高度为0px.它只是将焦点从EditText移开.
  3. 启动App时,焦点位于RelativeLayout,而不是EditText(因此其中没有闪烁的光标.)
  4. 当用户单击Button I时,只需使用RelativeLayout上的requestFocus()调用将焦点移动到RelativeLayout.
  5. 当用户点击EditText时,会出现键盘.我可以输入文字.

我想要实现的目标

  1. 如果我在键盘可见时改变手机的方向,那么在取消定位后,键盘应保持不变.
  2. 如果键盘是可见的,其他一些活动就会出现,例如闹钟,Facebook聊天头,打开通知区域的东西,锁定解锁设备等等.然后返回到示例应用程序键盘应该是可见的.

我是如何实现这一目标的

  1. 在onSaveInstanceState()中,我检查焦点是否在EditText上,然后在Bundle中放置一个布尔变量.
  2. 在onStop()中,我设置了一个布尔标志wasEditing = true.
  3. 在onRestoreInstanceState()中,我检查了Bundle是否在onSaveInstanceState()中设置了标志值.如果是,那么我就是wasEditing = true.
  4. 在onResume()中,我检查这个wasEditing,如果是,我请求焦点为EditText.
  5. 之后我打电话 imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT,resultRec)

我遇到问题的地方
有时在执行此调用后,键盘在少数情况下不可见,例如在方向更改期间.
当我把日志我发现这个函数返回false
但是,如果我有这样的showSoftInput()电话使用100毫秒的延迟一些mEditText.postDelayed()onResume()一切工作正常.

问题 在什么情况下此函数返回false并且为什么延迟有效?

注意 虽然我已经使用延迟解决了我的问题,但我仍然想知道为什么它表现得那样.

keyboard android android-softkeyboard android-input-method

8
推荐指数
1
解决办法
4490
查看次数

关闭/隐藏活动状态onStop上的Android软键盘

我的布局中有一个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)

android android-softkeyboard android-input-method

8
推荐指数
1
解决办法
3699
查看次数