`
longgangbai
  • 浏览: 7252920 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Android界面加载完成后自动弹出软键盘的解决方案

阅读更多

       在android中有多个可供输入的控件时候,加载之后,第一个可输入控件获取焦点。因此加载完毕输入软键盘弹出,采用获取焦点触摸模式可以解决问题,特此机制。

只需要在最外层的容器中添加以后语句即可。

    android:focusable="true"

    android:focusableInTouchMode="true"
例如:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="
http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:gravity="fill"
 >
 <include android:layout_width="fill_parent"
    android:layout_height="40dp"
     layout="@layout/query_ems_header"/>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  
android:focusable="true"
  android:focusableInTouchMode="true"
  >
  <EditText
   android:id="@+id/tv_ems_code"
   android:layout_width="0dip"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   >
  </EditText>
  <Button
      android:id="@+id/btn_scanner_coder"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_marginLeft="@dimen/common_view_margin"
      android:background="@drawable/scanner"
      />
 </LinearLayout>
    <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">

  <Spinner
      android:id="@+id/spinner_common_companys"
      android:layout_width="0dip"
      android:layout_weight="1"
      android:layout_height="wrap_content"
      >
  </Spinner>
  <EditText
   android:id="@+id/tv_ems_company_name"
   android:layout_width="0dip"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:hint="快递公司-拼音"
    />
 </LinearLayout>
 <LinearLayout
  android:layout_width="fill_parent"
  android:layout_height="wrap_content">
  <Button
   android:id="@+id/btn_save"
   android:layout_width="0dip"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:text="保存">
  </Button>
  <Button
   android:id="@+id/btn_query"
   android:layout_width="0dip"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:text="查询" />
 </LinearLayout>
 <ListView android:id="@+id/lv_emsDetail"
     android:layout_width="fill_parent"
     android:layout_height="match_parent"
     android:layout_gravity="center_vertical"
     android:choiceMode="singleChoice"
     android:background="@drawable/btn_bg">
    
 </ListView>
</LinearLayout>

详细看上述红色代码,即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics