關於android:focusable屬性


http://www.cnblogs.com/Gaojiecai/archive/2013/06/18/3142783.html

 

Android屬性 android:focusableInTouchMode

這個屬性的意思很明顯,就是可以通過touch來獲得focus。在手機上開發用的不多,因為大多手機都是觸摸式的。最近一個TV上的應用需要用到。

     一個界面上有一個自定義個button,我需要進入這個界面就高亮這個button。但是用遙控選擇這個程序進入能正常顯示,用鼠標點擊進入就沒有高亮的效果。最后添加上這個屬性,效果出來了。

     可見,click事件和touch事件在焦點處理上是不同的。

 


 

 

Android 如何讓EditText不自動獲取焦點

分類: Android

在項目中,一進入一個頁面, EditText默認就會自動獲取焦點。

那么如何取消這個默認行為呢?

 

在網上找了好久,有點 監聽軟鍵盤事件,有點 調用 clearFouse()方法,但是測試了都沒有! xml中也找不到相應的屬性可以關閉這個默認行為

 

解決之道:在EditText的父級控件中找一個,設置成

   android:focusable="true"  
   android:focusableInTouchMode="true"

這樣,就把EditText默認的行為截斷了!

 

 

<LinearLayout 
        style="@style/FillWrapWidgetStyle"
        android:orientation="vertical"
        android:background="@color/black"
        android:gravity="center_horizontal"
        
        android:focusable="true"  
        android:focusableInTouchMode="true"
        >
        <ImageView
            android:id="@+id/logo"
            style="@style/WrapContentWidgetStyle"
            android:background="@drawable/dream_dictionary_logo"
          />
        <RelativeLayout 
            style="@style/FillWrapWidgetStyle"
            android:background="@drawable/searchbar_bg"
            android:gravity="center_vertical"
            >
            <EditText
                android:id="@+id/searchEditText"
               style="@style/WrapContentWidgetStyle"
               android:background="@null"
               android:hint="Search"
               android:layout_marginLeft="40dp"
               android:singleLine="true"
             />
            
        </RelativeLayout>
        
    </LinearLayout>

來自:http://blog.csdn.net/woshicaixianfeng/article/details/7261718   灰常感謝這位同學。。。

 

還有一個方法也可以非常簡單的實現這個功能:

EditText對象的clearFocus();

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(editMsgView.getWindowToken(), 0);(關閉軟鍵盤。。。)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM