問題描述
在我的應用程序中,我所有屏幕的第一個視圖是 EditText,所以每次我進入屏幕時,屏幕鍵盤都會彈出.手動單擊 EditText 時如何禁用此彈出窗口并啟用它????
In my app the first view of all my screens is an EditText, so every time i go to a screen the onscreen keypad pops up. how can i disable this popingup and enable it when manually clicked on the EditText????
eT = (EditText) findViewById(R.id.searchAutoCompleteTextView_feed);
eT.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus){
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(eT.getWindowToken(), 0);
}
}
});
xml代碼:
<ImageView
android:id="@+id/feedPageLogo"
android:layout_width="45dp"
android:layout_height="45dp"
android:src="@drawable/wic_logo_small" />
<Button
android:id="@+id/goButton_feed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/go" />
<EditText
android:id="@+id/searchAutoCompleteTextView_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/goButton_feed"
android:layout_toRightOf="@id/feedPageLogo"
android:hint="@string/search" />
<TextView
android:id="@+id/feedLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/feedPageLogo"
android:gravity="center_vertical|center_horizontal"
android:text="@string/feed"
android:textColor="@color/white" />
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ButtonsLayout_feed"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:id="@+id/feedButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/feed"
android:textColor="@color/black" />
<Button
android:id="@+id/iWantButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/iwant"
android:textColor="@color/black" />
<Button
android:id="@+id/shareButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/share"
android:textColor="@color/black" />
<Button
android:id="@+id/profileButton_feed"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_margin="0dp"
android:layout_weight="1"
android:background="@color/white"
android:text="@string/profile"
android:textColor="@color/black" />
</LinearLayout>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/feedListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ButtonsLayout_feed"
android:layout_below="@id/feedLabel"
android:textSize="15dp" >
</ListView>
第三個視圖(EditText)是焦點所在.
the third view (EditText) is where the focus is.
推薦答案
最好的解決方案在于Project Manifest文件(AndroidManifest.xml),在activity<中添加如下屬性/code> 構造
The best solution lies in the Project Manifest file (AndroidManifest.xml), add the following attribute in the activity
construct
android:windowSoftInputMode="stateHidden"
android:windowSoftInputMode="stateHidden"
<小時>
示例:
<activity android:name=".MainActivity"
android:windowSoftInputMode="stateHidden" />
說明:
- 當 Activity 成為用戶關注的焦點時,軟鍵盤的狀態(無論是隱藏還是可見).
- 對 Activity 的主窗口所做的調整——無論是縮小它的大小以便為軟鍵盤騰出空間,還是當窗口的一部分被軟鍵盤覆蓋時,它的內容是否平移以使當前焦點可見.
引入于:
- API 級別 3.
文檔鏈接
注意:此處設置的值(stateUnspecified"和adjustUnspecified"除外)會覆蓋主題中設置的值.
這篇關于在edittext上如何禁用鍵盤彈出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!