android常用方法汇总-更新中

横屏时限制输入法全屏的方法

一是在源码里进行修改。

   frameworks/base/core/java/android/inputmethodservice/InputMethodService.java 

           1、 在updateFullscreenMode(..)中,将boolean isFullscreen = mShowInputRequested && onEvaluateFullscreenMode();

                                                               改为boolean isFullscreen=false;

           2、也可以:直接修改onEvaluateFullscreenMode()的返回值为false    <自定义输入法时,可以直接重写之,就不必在源码中修改了>


二是在自己EditText的xml里加上属性

 android:imeOptions="flagNoExtractUi"

防止EditTextView 或者AutoCompleteTextView默认获取焦点的方法

          因为进入画面时是默认得到焦点的,要想不让其默认获得焦点,可以在控件前加一个o像素的layout,并设置他先得到焦点,也可以将其控件属性加入android:nextFocusUp="@+id/其它控件ID"无非就是想尽办法将这两个控件的焦点置于其他焦点之后

      基本代码如下

        <LinearLayout
            android:layout_width="0px"
            android:layout_height="0px"
            android:focusable="true"
            android:focusableInTouchMode="true" >
        </LinearLayout>

        <AutoCompleteTextView
            android:id="@+id/et_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/map_common_10dp"
            android:layout_weight="3"
            android:background="@null"
            android:hint="@string/map_page_location_edit_hint"
            android:imeOptions="flagNoExtractUi"
            android:maxLength="20"
            android:paddingLeft="@dimen/map_common_10dp"
            android:singleLine="true"
            android:textColor="@color/map_common_color_767676"
            android:textSize="@dimen/map_common_26px" />

     这样就不会默认获取焦点了。


隐藏输入法键盘的方法


InputMethodManager inputMethodManager =(InputMethodManager)activity.getApplicationContext().
			getSystemService(Context.INPUT_METHOD_SERVICE); 
		
EditText editText = (EditText)findViewById(R.id.xxxx); 
inputMethodManager.hideSoftInputFromWindow(editText.getWindowToken(), 0); //隐藏

你可能感兴趣的:(android,调试,android应用)