相关疑难解决方法(0)

关闭/隐藏Android软键盘

我的布局中有一个EditText和一个Button.

在编辑字段中写入并单击后Button,我想隐藏虚拟键盘.我假设这是一段简单的代码,但我在哪里可以找到它的一个例子?

android soft-keyboard android-layout android-softkeyboard android-input-method

3641
推荐指数
59
解决办法
144万
查看次数

自动显示键盘

请解释一下软键盘的问题.例如,我在我的活动或对话片段或片段活动上有一个EditText,无论如何.这里是:

<EditText
    android:id="@+id/edPswrd"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textPassword" >

    <requestFocus />
</EditText>
Run Code Online (Sandbox Code Playgroud)

当它第一次显示我没有看到软键盘并且必须按editText才能获得焦点并且键盘出现.另一个活动是不同的,当它出现在屏幕上时,键盘在没有任何帮助的情况下加载.我以为

<requestFocus />

意味着EditText将被聚焦并且键盘将出现,但我错了.

如何管理哪些组件将获得焦点,键盘将自动显示.

java keyboard android focus android-activity

42
推荐指数
5
解决办法
5万
查看次数

SoftKeyboard不会显示新显示的片段

我有一个FragmentActivity,最初显示一个片段,上面有几个按钮.单击其中一个按钮时,FragmentActivity将显示一个包含某些editText字段的新片段.当我显示带有editText字段的新片段时,我似乎无法显示软输入键盘.

在清单上使用windowSoftInput模式,因为它立即显示键盘.

 android:windowSoftInputMode="stateUnchanged"
Run Code Online (Sandbox Code Playgroud)

我试过用

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)

无济于事.以下是我在Activity中显示新片段的方法:

public void clickHandler(View view) {
        switch (view.getId()) {
        case R.id.login:
            loginFragment = new LoginFragment();
            FragmentTransaction transaction = getSupportFragmentManager()
                    .beginTransaction();

            transaction.replace(R.id.fragment_container, loginFragment);
            transaction.addToBackStack(null); 
            transaction.commit();
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);  
            break;
Run Code Online (Sandbox Code Playgroud)

...

我也尝试从片段的onCreate中调用setSoftInputMode,但是效果不佳.认为这是一个时间问题,我用handler.postDelayed尝试了它,但也没有用.它看起来像这样:

onResume...    
Handler handler = new Handler();
            Runnable runnable = new Runnable() {

                @Override
                public void run() {
                    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);                
                }
            };

            handler.postDelayed(runnable, 1000);
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.谢谢.

android android-softkeyboard android-fragments

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

如何在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万
查看次数

在 Fragment 中显示/隐藏软键盘事件

有很多关于查找显示/隐藏软键盘事件的帖子。我发现自己处于需要根据片段中的软键状态更改图标的情况。

我尝试实现 onMeasure,但无法在片段中覆盖它。是否有一种(相对)无痛的方法可以在我的片段中获得干净的显示/隐藏软键盘事件,或者我应该放弃发货?

android android-softkeyboard

5
推荐指数
1
解决办法
5228
查看次数

片段启动时如何将焦点设置为editText?

MyFgment出现在屏幕上,我想设置光标焦点上EditTextMyFragment自动。我试过了EditText.requestFocus(),但它不专注于EditText. 我能怎么做??

android setfocus android-edittext

5
推荐指数
2
解决办法
2560
查看次数