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>

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值