2016-02-29 140 views
4

這是一個相當簡單的問題,但我無法相信我發現的所有答案都不起作用。Android從所有視圖中刪除焦點

我有兩個EditText佈局和窗口的底部只是一些剩餘的空白。當用戶點擊窗口的空白部分時,我想讓每個EditText放鬆焦點。所以我的猜測是,我必須把事情根ViewOnTouchListener

rootView.setOnTouchListener(new View.OnTouchListener() { 

    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
      // Put something here 
    } 
}); 

我已經試過幾件事情:如建議

  • 從佈局View請求焦點的地方,其實是重點關注EditText之一。

  • 我也試着設置setFocusable兩個EditText s到false但我無法把他們帶回true之後。

  • 我也嘗試了簡單rootView.clearFocus(),但它也給後面的焦點一個EditText

編輯:我的EditText框是這麼多線,因爲我需要返回一個是我目前不能使用「完成」鍵盤按鍵。

+0

你想如何管理你的鍵盤?所以當關注edittext時它是可見的,所以它不會消​​失? –

+0

你有沒有在你的根視圖上試過'android:focusableInTouchMode =「true」'?請張貼您的佈局文件。 –

+0

'rootView'是你的editText?因爲你需要在你的editText上調用['clearFocus()'](http://developer.android.com/reference/android/view/View.html#clearFocus%28%29)。 – Strider

回答

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/ll_root_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

LinearLayout llRootView = findViewBindId(R.id.ll_root_view); 
llRootView.clearFocus(); 

我用這個時候已經完成了更新個人資料信息,並刪除所有焦點從EditText上在我的佈局

====>更新:在父版面內容我的EditText添加一行:

android:focusableInTouchMode="true"