gpt4 book ai didi

android - 在edittext上如何禁用键盘弹出?

转载 作者:IT老高 更新时间:2023-10-28 13:09:18 25 4
gpt4 key购买 nike

在我的应用程序中,我所有屏幕的第一个 View 是 EditText,所以每次我进入屏幕时,屏幕键盘都会弹出。手动单击 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>

第三个 View (EditText)是焦点所在。

最佳答案

最好的解决方案在于Project Manifest文件(AndroidManifest.xml),在activity构造中添加如下属性

android:windowSoftInputMode="stateHidden"


示例:

    <activity android:name=".MainActivity" 
android:windowSoftInputMode="stateHidden" />

说明:

  • 当 Activity 成为用户关注的焦点时,软键盘的状态(无论是隐藏还是可见)。
  • 对 Activity 的主窗口所做的调整——无论是缩小它的大小以便为软键盘腾出空间,还是当窗口的一部分被软键盘覆盖时,它的内容是否平移以使当前焦点可见。

引入于:

  • API 级别 3。

Link to the Docs

注意:此处设置的值(“stateUnspecified”和“adjustUnspecified”除外)会覆盖主题中设置的值。

关于android - 在edittext上如何禁用键盘弹出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10611833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com