必承其重 | 欲带皇冠 2009-10-12 15:03 采纳率: 0%
浏览 211
已采纳

停止 EditText 在活动启动时获得关注

I have an Activity in Android, with two elements:

  1. EditText
  2. ListView

When my Activity starts, the EditText immediately has input focus (flashing cursor). I don't want any control to have input focus at startup. I tried:

EditText.setSelected(false);

No luck. How can I convince the EditText to not select itself when the Activity starts?

转载于:https://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup

  • 写回答

1条回答 默认 最新

  • 谁还没个明天 2009-11-02 15:49
    关注

    Excellent answers from Luc and Mark however a good code sample is missing. Adding the tag android:focusableInTouchMode="true" to <LinearLayout> like the following example will fix the problem.

    <!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
    <LinearLayout
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:layout_width="0px" 
        android:layout_height="0px"/>
    
    <!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
    to prevent the dummy from receiving focus again -->
    <AutoCompleteTextView android:id="@+id/autotext"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:nextFocusUp="@id/autotext" 
        android:nextFocusLeft="@id/autotext"/>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码