zoukankan      html  css  js  c++  java
  • Android 让文本输入框默认不获取焦点

    项目中有个检索功能,页面上有个EditText输入框,打开页面后,焦点默认在EditText上,这样的话软键盘默认就会显示出来,占据大半个屏幕。

    后来想办法将这个给去掉了,原先考虑着将焦点赋给页面上的其他组件(页面上还有时间选择组件、按钮组件等),方法如下:

      <EditText
            android:id="@+id/topical_content"
            android:layout_width="260dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@id/topical_image"
            android:hint="请输入主题"
            android:nextFocusLeft="@+id/其它控件ID"
            android:nextFocusUp="@+id/其它控件ID"
            android:singleLine="true"
            android:textSize="12sp"/>

    另一种方法是在EditText前面放置一个看不到的LinearLayout,让它率先获取焦点,代码如下:

      <LinearLayout
            android:layout_width="0px"
            android:layout_height="0px"
            android:focusable="true"
            android:focusableInTouchMode="true" />

    还有一种方法是在manifest中设置对activity的控制(此方法从网上找的,效果没有试验,不知道可不可以,列出来给大家参考下)

    <activity ...  android:windowSoftInputMode="stateAlwaysHidden|adjustResize" />

    本人项目中用的是第二种方法,即在EditText前面加了一个Linearlayout,让它让率先获取焦点,实现了我想要的结果。

  • 相关阅读:
    poj 1573 Robot Motion
    poj 1035 Spell checker
    poj 3080 Blue Jeans
    poj 3468 A Simple Problem with Integers(线段树区间更新)
    poj 3687 Labeling Balls(拓补排序)
    poj 3295 Tautology
    poj 1062 昂贵的聘礼
    hdu 1170 Balloon Comes!
    hdu 1215 七夕节
    OCJP-试题集合 | 对象的比较
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5916644.html
Copyright © 2011-2022 走看看