2013-04-09 113 views
1

我有一個EditText與imeOptions="actionSearch"。現在,當我點擊EditText時,鍵盤不會在一些HTC設備中彈出,如HTC Desire S & HTC Incredible。 XML的EditText情況如下:在HTC Desire S上,軟鍵盤沒有彈出EditText焦點

<com.myapp.utilities.font.DroidSansEditText 
        android:id="@+id/txtSearchByName" 
        android:layout_width="0dp" 
        android:layout_height="match_parent" 
        android:layout_weight="0.60" 
        android:background="@drawable/edittext" 
        android:ellipsize="end" 
        android:gravity="left|center_vertical" 
        android:hint="@string/provider_practice" 
        android:imeOptions="actionSearch" 
        android:inputType="textCapWords" 
        android:paddingLeft="10dp" 
        android:paddingRight="5dp" 
        android:singleLine="true" 
        android:tag="byName" 
        android:textColor="#a19d93" 
        android:textSize="15.5sp" /> 

DroidSansEditText是具有droid-sans font定製EditText。該DroidSansEditText情況如下:

public class DroidSansEditText extends EditText { 
    public DroidSansEditTextView(Context context) { 
     super(context);  
    } 

    public DroidSansEditTextView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public DroidSansEditTextView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    @Override 
    public void setTypeface(Typeface tf, int style) { 
     if (!isInEditMode()) { //For Graphical layout of xml in eclipse 
      // here Bold style is handled. Same way we can handle italic style 
      if (style == 1) { // if bold (Style Constant, normal = 0 | bold = 1 
           // | italic = 2) 
       tf = Typeface.createFromAsset(getContext() 
         .getApplicationContext().getAssets(), 
         "DroidSans-Bold.ttf"); 
      } else { 
       tf = Typeface.createFromAsset(getContext() 
         .getApplicationContext().getAssets(), "DroidSans.ttf"); 
      } 
      super.setTypeface(tf, 0); 
     } 
    } 
} 

回答

1

也許是因爲其實你沒有設置字體,如果這是的EditText編輯模式?

我的意思是,爲什麼你需要的是:

if (!isInEditMode()) 

如果在編輯模式下,你要設置其他字體,寫其他聲明,並在其中設置該其他字體。因爲至今爲止 - 如果TextView處於編輯模式,則不會調用super.setTypeface();如果TextView處於編輯模式,則不調用super.setTypeface()。所以你只是重寫方法而不做任何事情。請嘗試讓我知道

+0

感謝您的回覆。其實我不知道EditMode對EditText有什麼作用。我把這種情況,因爲如果沒有在Eclipse中,我不能在圖形模式下正確地看到EditText。 – hemu 2013-04-16 15:24:33

+0

然後提供else語句,如果你在其他地方調用super.setTypeFace()例如 – 2013-04-19 06:55:12

+0

。另外爲了確保我使用Input'InputMethodManager'通過觸摸editext顯式地打開了鍵盤。謝謝。 – hemu 2013-04-19 09:27:12

0

有一種方法來顯示和隱藏鍵盤時,單擊編輯文本鍵入的東西。找到隱式顯示鍵盤的行下方。

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 

這裏編輯文字在編輯文本你using.and隱藏它觸摸時其他地方在屏幕上只是this.Take屏幕的最頂部的佈局和實施本上的觸控方法你頂部佈局,以便在觸摸到其他位置時除了編輯文本鍵盤被取消。

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 

mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);