在啓動Activity時,如何隱藏輸入法

更新於20140110 現在最常用的解決方法是 在佈局的獲取焦點的元素前面加上這段

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

==============================================

一開始以爲這個問題很好解決,沒想到研究了半天,都沒找到解決方法

問題:

I have an Android Activity, with two elements:

  1. EditText
  2. ListView

When my Activity starts, the EditText immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. 

解決方法:

http://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup


Exist more simple solution. Set in your parent layout next attributes:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainLayout"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true" >

And now, when activity starts this layout getting default focus.

Also we can remove focus from children views in runtime (e.g. after finishing child editing):

findViewById(R.id.mainLayout).requestFocus();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章