31

我的布局中有一个Fragment(兼容版本) 。EditText我正在使用 aViewFlipper在片段之间翻转。当我到达这个特定Fragment的,软键盘会自动打开。这不是我想要的。这是我试图阻止或隐藏它的原因。

试过:

android:descendantFocusability="beforeDescendants" 

在片段的主视图上

试过:

android:windowSoftInputMode="stateHidden"

android:windowSoftInputMode="stateAlwaysHidden"

在活动清单中

试过:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mViewPager.getChildAt(position).getWindowToken(), 0);

在我的 ViewPager 的 OnPageChangeListener 上

试过:

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(voucherView.findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);

在我的片段中的 onCreateView

试过:

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);

在我的片段中的 onStart

试过:

voucherView.findViewById(R.id.redeem_mobile_number).clearFocus();

在我的片段中的 onCreateView

在我看来, onPageChangeListener 是这样做的地方,因为其他调用发生在软键盘实际打开之前。任何帮助都会很棒。

4

7 回答 7

81

这篇文章有一个解决问题的方法。

答案是添加android:focusableInTouchMode="true"LinearLayout包含EditText. 现在它不会自动调出软键盘。

于 2012-07-05T09:07:23.847 回答
8
 <LinearLayout 
         android:id="@+id/layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:focusable="true" 
        android:focusableInTouchMode="true"         
        >

    <EditText
        android:id="@+id/retailer_search_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         />

</LinearLayout>

跟着它走。并且 EditText 应该在 LinearLayout 内。

于 2012-11-19T15:02:53.107 回答
5

你试过这个吗?

<activity
    android:name=".YourActivityName"
    android:configChanges="keyboardHidden|orientation"
    android:windowSoftInputMode="stateHidden" />

编辑:

试试这个(我现在很糟糕,但试试这个):)

    Thread splashTread = new Thread() {
        @Override
        public void run() {
            try {

                sleep(1);
            } catch (InterruptedException e) {
                // do nothing
            } finally {
                runOnUiThread(new Runnable() {
                    public void run() {
                        InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(youreditText.getWindowToken(), 0);

                    }
                });

            }
        }
    };
    splashTread.start();
于 2012-07-04T11:04:42.477 回答
1

将此添加到您在keyboardHidden 中的活动标签中AndroidManifest.xml :不会让它自动打开软输入键盘。

android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|stateHidden"
于 2016-05-09T07:11:53.423 回答
1

当我单击片段视图中的编辑文本时,我有一个令人不安的软键盘弹出并向上推所有视图(我的应用程序是嵌套片段的应用程序 - 片段中的片段)

我在这里和互联网上尝试了十几种解决方案,但除此之外没有任何帮助,即EditText在 XML 中编辑自身(不是上面的视图/不是清单/不是覆盖创建活动/不是任何其他)

通过在 EditText 的 xml 中添加android:focusableInTouchMode="false"行。

我在这个线程上从 ACengiz 借了解决方案

在android中单击edittext时如何阻止虚拟键盘?

只有2个人投票给他?尽管对我来说,在头疼了几个小时之后,这是一个节省

于 2016-05-27T17:57:33.853 回答
0

这对我有用。

edittext.setInputType(InputType.TYPE_NULL);      
if (android.os.Build.VERSION.SDK_INT >= 11)   
{  
    edittext.setRawInputType(InputType.TYPE_CLASS_TEXT);  
    edittext.setTextIsSelectable(true);  
}
于 2013-05-10T08:41:57.003 回答
0

试试这个

exitText.setFocusableInTouchMode(true);
于 2015-01-04T07:35:31.980 回答