日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android控制EditText的焦点

發布時間:2023/12/20 Android 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android控制EditText的焦点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在項目中,一進入一個頁面, 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);(關閉軟鍵盤。。。)

總結

以上是生活随笔為你收集整理的Android控制EditText的焦点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。