2012-07-04 84 views
23

我有Fragment(兼容版本)與其EditText在其佈局。我正在使用ViewFlipper在片段之間翻轉。當我到達這個特定Fragment時,軟鍵盤會自動打開。這不是我想要的。這是我試圖阻止或隱藏它的原因。EditText自動打開軟鍵盤時使用ViewPager可見碎片

嘗試:

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是做這個的地方,因爲其他電話前軟發生鍵盤實際上是打開的。任何幫助都會很棒。

+0

要隱藏片段在try鍵盤: InputMethodManager IMM =(InputMethodManager)getSherlockActivity()getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(inputSearch.getWindowToken(),0); P.S inputSearch是EditText字段 –

回答

60

This後有一個解決問題的辦法。

答案是將android:focusableInTouchMode="true"添加到LinearLayout,其中包含EditText。現在它不會自動彈出軟鍵盤。

+0

非常好,短而乾淨。謝謝 –

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(); 
+0

組合android:configChanges和android:windowSoftInputMode是重要的。 –

+0

剛剛嘗試過,並沒有幫助 –

+0

我的第一次滑動到Fragment的視圖時,編輯工作正常,但之後它不起作用。這絕對不是這樣做的正確方法 –

7
<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中。

+0

我想要的是如何在顯示鍵盤後將焦點設置在搜索字段上! –

0

這對我有效。

edittext.setInputType(InputType.TYPE_NULL);  
if (android.os.Build.VERSION.SDK_INT >= 11) 
{ 
    edittext.setRawInputType(InputType.TYPE_CLASS_TEXT); 
    edittext.setTextIsSelectable(true); 
} 
0

嘗試這個

exitText.setFocusableInTouchMode(true); 
1

添加到您的活動代碼在AndroidManifest.xml keyboardHidden:不會讓它自動打開軟鍵盤輸入。

android:configChanges="orientation|keyboardHidden|screenSize" 
android:windowSoftInputMode="stateAlwaysHidden|adjustResize|stateHidden" 
1

我有一個軟鍵盤令人不安彈出,推動所有的意見,當我點擊的片段視圖編輯文本(我的應用程序是嵌套的片段的應用程序 - 在片段片段)

我試着在這裏和在互聯網上,但沒有一打的解決方案幫助除了這一點,這是編輯EditText本身在XML(不高於視圖/不清單/不overwride上創建活動/沒有任何其他)

加入android:focusableInTouchMode="false"行到您的EditText的xml。

我借用ACengiz在此線程

how to block virtual keyboard while clicking on edittext in android?

只有2人投票給他的解決方案嗎?雖然對我來說是一個頭痛小時後金丹

相關問題