gpt4 book ai didi

android - requestFocus 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:53:59 25 4
gpt4 key购买 nike

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="20dp" >

<AutoCompleteTextView
android:id="@+id/autocomplete_zone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:dropDownVerticalOffset="0.2dp"
android:ems="10"
android:hint="@string/zone_hint"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:popupBackground="#00ffffff"
android:textColor="#ffffff"
android:textColorHint="#ffffff" >

<requestFocus />
</AutoCompleteTextView>

<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignBottom="@id/autocomplete_zone"
android:layout_alignRight="@id/autocomplete_zone"
android:layout_alignTop="@id/autocomplete_zone"
android:paddingBottom="5dp"
android:visibility="invisible" />
</RelativeLayout>

在上面的标记中

<requestFocus />

不起作用。 Activity 启动时, TextView 未获得焦点。这是因为覆盖 TextView 的进度条吗?有什么解决办法吗?

最佳答案

我通常使用以下设置焦点:将以下属性添加到您的 xml-layout

<AutoCompleteTextView 
android:focusable="true"
android:focusableInTouchMode="true">
</AutoCompleteTextView>

并以编程方式设置焦点

((AutoCompleteTextView) findViewById(R.autocomplete_zone)).requestFocus();

f.e.在 onResumeonWindowChanged

public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);

if (hasFocus) {
((AutoCompleteTextView) findViewById(R.autocomplete_zone)).requestFocus();
}
}

关于android - requestFocus 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19820846/

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