标签: android-softkeyboard

Android显示软键与showSoftInput无法正常工作?

我创建了一个简单的应用程序来测试以下功能.当我的活动启动时,需要在软键盘打开的情况下启动它.

我的代码不起作用?!

我已经在清单中尝试了各种"状态"设置,并且在InputMethodManager(imm)的代码中尝试了不同的标志.

我已将该设置包含在AndroidManifest.xml中,并在唯一活动的onCreate中显式调用.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.mycompany.android.studyIme"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".StudyImeActivity"
                  android:label="@string/app_name" 
                  android:windowSoftInputMode="stateAlwaysVisible">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>
Run Code Online (Sandbox Code Playgroud)

...主要布局(main.xml)......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <EditText
        android:id="@+id/edit_sample_text"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:hint="@string/hello"
        android:inputType="textShortMessage"
    />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

......和代码......

public class StudyImeActivity extends Activity {
    private EditText mEditTextStudy;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) …
Run Code Online (Sandbox Code Playgroud)

android show android-softkeyboard android-input-method

26
推荐指数
8
解决办法
4万
查看次数

Android中的完成键盘上隐藏软键盘?

我正在努力使用软键盘上的完成按钮.我无法通过软键盘完成按键来隐藏键盘.从另一个按钮,它完美地与

imm.hideSoftInputFromWindow(editText.getApplicationWindowToken(), 0);

但onKeyListener不能按我想要的方式运行.当我点击editText时,软键盘会显示,其内容将从字符中清除.

谢谢收听!

main.xml:

<EditText 
    android:id="@+id/answer" 
    android:layout_gravity="center_horizontal" android:textSize="36px"
    android:inputType="phone"
    android:minWidth="60dp" android:maxWidth="60dp"
/>
Run Code Online (Sandbox Code Playgroud)

Java文件:

private EditText editText;
//...
editText = (EditText)findViewById(R.id.answer);
editText.setOnClickListener(onKeyboard);
editText.setOnKeyListener(onSoftKeyboardDonePress);
//...

// method not working:
private View.OnKeyListener onSoftKeyboardDonePress=new View.OnKeyListener() 
{
    public boolean onKey(View v, int keyCode, KeyEvent event) 
    {
        if (event.getKeyCode() == KeyEvent.FLAG_EDITOR_ACTION)
        {
            // code to hide the soft keyboard
            imm = (InputMethodManager) getSystemService(
                Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText.getApplicationWindowToken(), 0);
        }
        return false;
    }
};

private View.OnClickListener onKeyboard=new View.OnClickListener() 
{
    public void onClick(View v) 
    {
        editText.setText("");
    }
}; …
Run Code Online (Sandbox Code Playgroud)

android soft-keyboard android-softkeyboard

25
推荐指数
2
解决办法
3万
查看次数

Android - 软键盘将我的活动布局推出屏幕

我的活动的布局如下所示.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <FrameLayout android:id="@+id/title_bar"
      android:layout_width="fill_parent"
      android:layout_height="25dip"
      android:background="@drawable/bg_title" />

   <LinearLayout android:id="@+id/main"
      android:width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
         <ListView android:id="@+id/android:list"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
         <TextView android:id="@+id/android:empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
      </FrameLayout>
   </LinearLayout>

   <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="50dip" >
      <EditText android:id="@+id/query"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:hint="Enter some search terms"
         android:singleLine="true" 
         android:layout_weight="1" />
      <Button android:id="@+id/btn_hide"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:background="@drawable/btn_hide"
         android:layout_marginLeft="6dip" />
   </LinearLayout>
 </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

因此,搜索框固定在屏幕的底部.

但是,当用户单击EditText时,软键盘会显示并将布局推出屏幕,但搜索框除外.

我刚刚开始使用Android,所以我在这里做错了什么?

android android-softkeyboard android-edittext

25
推荐指数
3
解决办法
2万
查看次数

以编程方式在ViewPager.OnPageChangeListener onPageSelected()中隐藏软键盘?

我有一个带标签的ViewPager + ActionBar.当我"滑动"到另一个标签时,我想隐藏软键盘,但我无法弄清楚如何.

我已经将我的Activity传递给了FragmentPageAdapter的构造函数,所以我可以调用它

 activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)

但它没有做任何事情(并且它位于代码的可到达区域)...帮助?

android android-softkeyboard android-fragments android-viewpager

25
推荐指数
3
解决办法
2万
查看次数

软键盘隐藏动作栏

我有一个简单的活动,文本视图后跟两个编辑文本.当我开始输入时,软键盘会向上推动布局并隐藏操作栏,我将无法选择/复制/粘贴文本.

我的活动如下:

正常活动视图

当我开始输入时,操作栏会被隐藏,就像这样 - 更重要的是,请注意,即使文本突出显示,也会丢失正常的复制粘贴栏:

缺少操作栏和复制/粘贴栏

我该怎么做才能确保操作栏不隐藏?

  • 我已经尝试了一些来自SO的其他技巧(例如使用滚动视图),但没有一个工作.
  • 该应用程序是使用带有抽屉活动的Android Studio 1.4.1向导创建的.
  • 在我的活动清单中,我使用的是adjustPan.我不想使用adjustResize.

    android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

我的活动在这里:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/navigation_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        tools:context=".MainActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/app_theme.app_bar_overlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:popupTheme="@style/app_theme.popup_overlay" />

        </android.support.design.widget.AppBarLayout>

        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/activity_margin"
            android:fillViewport="true"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:background="@android:color/darker_gray"
                android:text="My holiday story here." />

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/activity_margin" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/gap_normal"
                android:gravity="top"
                android:text="My Holiday in Europe" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:gravity="top"
                android:text="My holiday …
Run Code Online (Sandbox Code Playgroud)

android android-softkeyboard android-activity android-actionbar android-appbarlayout

25
推荐指数
1
解决办法
2615
查看次数

当按下软键盘中的"完成"按钮时,如何失去编辑文本的焦点?

我的xml中有7个edittext框.我正在使用OnFocusChangeListener从edittext读取值,我正在使用该值进行计算.我想让我的edittext在我点击软键盘中的完成按钮时失去焦点.所以我可以得到edittext中的值.

android android-softkeyboard android-edittext

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

Android从EditText隐藏软键盘,同时不丢失光标

我已经到了这一点,这让我在那里,但并不完全.我有一个拨号器Fragment,其中包含所有常用Button的输入数字,包括退格键,因此我不需要软键盘.我还想让用户能够粘贴文本(长按...默认情况下工作正常),以及编辑已输入的内容,因此我需要光标.

我找到的最简单的方法是确保软键盘不会弹出,如果用户点击内部EditText是设置inputType为null - 但这也会杀死光标.

那么,我如何声明我EditText应该启动哪些命令以使我的EditText字段永远不会显示软键盘,无论用户尝试什么,但仍然保留粘贴功能和光标?

我也尝试android:windowSoftInputMode="stateAlwaysHidden"过我的清单,但无济于事.

android android-softkeyboard android-edittext

24
推荐指数
2
解决办法
3万
查看次数

如何在弹出键盘中禁用键预览(不在主软键盘布局中)?

禁用键预览很容易:只需调用setPreviewEnabled(false),这些烦人的小预览就不会再出现了.但是如果我将一个弹出式键盘附加到任何键上,那么这些预览将显示在该弹出窗口中:

qwerty.xml:

<Key android:codes="101" 
    android:keyLabel="E" 
    android:popupKeyboard="@xml/popup"
   android:keyTextSize="60sp"/>
Run Code Online (Sandbox Code Playgroud)

popup.xml:

<Row>
    <Key android:codes="-10000"
        android:keyLabel="test"
        android:keyOutputText="test"/>
</Row>
<Row>
    <Key android:codes="-10001"
        android:keyLabel="test2"
        android:keyOutputText="test2"/>
</Row>
Run Code Online (Sandbox Code Playgroud)

无法发布图片,但如果我长按字母'E'然后按test或test2按钮,他们将显示白键预览.

有没有办法禁用这些关键预览呢?

android keypreview android-softkeyboard custom-keyboard

24
推荐指数
1
解决办法
2880
查看次数

Android软键盘自定义"完成"按钮文字?

我知道我可以使用不同的东西设置我的"完成"按钮

EditText.setImeOptions();
Run Code Online (Sandbox Code Playgroud)

但是我如何将其设置为自定义文本?我可以指定我想要的文本吗?

android android-softkeyboard

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

在片段替换时显示/隐藏Android软键盘

我有一个片段活动.让我们说一个包含事物列表的列表片段.现在我想让用户添加一个东西,所以我使用FragmentManager用一个带有EditText的插入片段替换列表片段.EditText具有焦点,光标闪烁.但软键盘无法打开.反之亦然:如果用户输入了新内容并将其添加到列表中,我将插入片段替换为列表片段.但是,虽然没有EditText,键盘也不会关闭.

实现这个的正确方法是什么?我不敢相信我必须在所有过渡时手动显示和隐藏键盘?!

android fragment android-softkeyboard android-fragments

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