導航:首頁 > 操作系統 > 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控制項失去焦點相關的資料

熱點內容
php取伺服器url地址 瀏覽:291
linux時間調度演算法 瀏覽:767
單片機最小電路詳解 瀏覽:181
請求要求命令 瀏覽:802
電腦文件夾發微信顯示被佔用 瀏覽:289
手機怎麼看加密視頻 瀏覽:202
怎樣解壓手機es文件包 瀏覽:659
2017年學什麼編程 瀏覽:930
金融期貨pdf 瀏覽:690
程序員客棧的信息保密嗎 瀏覽:507
編程顯示器什麼意思 瀏覽:146
網路編程的就業 瀏覽:260
s7200編程入門 瀏覽:748
華潤萬家app為什麼進不去 瀏覽:250
後台運行app命令 瀏覽:873
通達信雲加密能破解 瀏覽:141
郵件保存成pdf 瀏覽:867
bbs網站java源碼下載百度雲 瀏覽:460
php無限極分類樹 瀏覽:275
什麼叫高分伺服器 瀏覽:814