1

我有一个带有imeOptions="actionSearch". 现在,当我单击 EditText 时,键盘不会在某些 HTC 设备中弹出,例如 HTC Desire S 和 HTC Incredible。EditText xml 如下:

<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是有的习俗EditTextdroid-sans fontDroidSansEditText 如下:

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);
        }
    }
}
4

2 回答 2

1

可能是因为如果此 EditText 处于编辑模式,实际上您没有设置字体?

我的意思是,你为什么需要那个:

 if (!isInEditMode())

如果在编辑模式下要设置另一个字体,请编写else语句并在其中设置另一个字体。

因为就目前而言 - 如果 TextView 处于编辑模式,您不会调用 super.setTypeface(); 所以你只需覆盖方法而不做任何事情。请尝试让我知道

于 2013-04-10T10:40:17.317 回答
0

There is a way to show and hide the keyboard when clicked on edit text to type something.Find below the lines for showing the keyboard implicitly.

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

mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

where edit Text is the Edit Text you are using.and to hide it when touched somewhere else on the screen just do this.Take the top most layout of your screen and implement this on on Touch method of your top layout so that when touched somewhere else other than the edit text keyboard gets dismissed.

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

mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0);
于 2013-08-31T19:42:42.547 回答