導航:首頁 > 操作系統 > android控制項失去焦點

android控制項失去焦點

發布時間:2024-06-29 17:10:30

android 一個布局裡面有三個EditText默認的游標是停在第一個上面的怎麼讓游標默認在第二個或第三個呢

在請求出現游標是,也就是在獲取焦點時:
editText.requestFocus();
清除游標,也就是失去焦點:
editText.clearFocus();

第一個設置失去焦點,第二或者第三個設置獲得焦點試試

另外還有:

使游標移動到指定的位置:
editText.setSelection(2);
輸入的參數是個整數

讓EditText不出現游標:
editText.setCursorVisible(false);

② android 輸入框失去焦點,怎樣讓鍵盤不自

1. 在activity layout xml文件中,EditText的前面定義:
<LinearLayout android:focusable="true" android:focusableInTouchMode="true" android:layout_width="0px" android:layout_height="0px" />

2. 在EditText中添加nextFocusUp與nextFocusLeft

<EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText" android:nextFocusUp="@id/editText" android:nextFocusLeft="@id/editText" />

③ android edittext輸入完成後讓游標消失

首先需要監聽輸入框的焦點變化,其次再根據焦點是否存在設置其游標顯示
代碼如下:其中editText是你的editText的id.
editText.setCursorVisible(true); --> 設置游標可見(默認), 為false即不可見
代碼如下:
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
boolean hasFocus = true;
if (hasFocus) {
editText.requestFocus(); //獲取焦點,游標出現
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);
editText.setCursorVisible(true);

} else {
editText.clearFocus();
editText.setCursorVisible(false);
}
}
});

④ 怎麼讓android 頁面失去焦點

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

1 解決之道:在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>


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

EditText對象的clearFocus();

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

3更多問題解決辦法請參考android學習手冊,例子、源碼、文檔全部搞定,採用androidstudo的目錄結構,360手機助手中下載。下面是截圖。

⑤ android 怎麼讓edittext失去焦點

1、在EditText的父布局中的布局文件中設置這兩行代碼
android:focusable="true"
android:focusableInTouchMode="true"
2、在代碼中設置EditText焦點通過setFocusable()和setFocusableInTouchMode() 不過這個好像不怎麼管用
3、如果你是不是想跳轉到有EditText的界面時自動彈出軟鍵盤的話 可以在功能清單文件(AndroidManifest.xml) 中的相對應activity節點中設置軟鍵盤彈出模式
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"

⑥ android 怎樣讓button失去焦點

三種方法可以試試。
1、button.setFocusable(false);
2、如果只是為了進入的時候不要讓某個控制項得到焦點,可以設置焦點到整個Layout。
3、也可以在屏幕的空白處 就是你的deittext的父容器(例如你把文本框放在了LinearLayout布局中)可以給父容器添加事件使其失去焦點。

閱讀全文

與android控制項失去焦點相關的資料

熱點內容
保存網路怎麼添加密碼 瀏覽:531
棉被怎麼壓縮 瀏覽:870
gt5手機版安卓怎麼下 瀏覽:890
羅技g413怎麼編程 瀏覽:770
小神的伺服器ip地址是什麼 瀏覽:661
程序員大爺采訪 瀏覽:323
廣聯達算量怎麼增加加密區 瀏覽:487
steam截屏圖片默認文件夾 瀏覽:184
java環境變數設置mac 瀏覽:170
安卓如何傳原圖到ipad 瀏覽:850
命令方塊手機版在哪裡 瀏覽:145
po如何進去伺服器 瀏覽:479
專門看美國劇情片網站 瀏覽:598
漏點的喪屍電影 瀏覽:864
html視頻聊天源碼 瀏覽:379
單片機網路運維 瀏覽:986
舌吻電影 瀏覽:453
單片機0ffh 瀏覽:405
機器人編程學習資料 瀏覽:149
被窩愛看大咖福利在線電影網 瀏覽:378