关于EditText获得焦点不弹出软键盘

论坛 期权论坛 脚本     
匿名技术用户   2021-1-5 08:50   34   0



XML中定义的xml



<EditText
android:id="@id/emergency_time"
style="@style/myEditStyle"
android:layout_width="match_parent"
android:layout_height="0.0dp"
android:layout_marginBottom="@dimen/vertical_spacing"
android:layout_marginLeft="@dimen/horizontal_spacing"
android:layout_marginRight="@dimen/horizontal_spacing"
android:layout_weight="1.0"
android:drawableRight="@drawable/calendar_onfocus"
android:gravity="center_vertical|left"
android:hint="突发情况发生时间"
android:paddingLeft="@dimen/horizontal_spacing"
android:paddingRight="@dimen/horizontal_spacing" />

/*********************************************************************/

1.设置获得焦点不弹起软键盘

1.1在XML中添加属性 android:inputType="none"

1.2在java代码中添加 emergency_time.setInputType(InputType.type_null);

2.设置获得焦点弹出对话框

class SelectEmergencyTime implements OnTouchListener {


@Override
public boolean onTouch(View v, MotionEvent event) {
showDialog();
return false;
}


}

emergencyTime.setOnTouchListener(new SelectEmergencyTime());
emergencyTime.setInputType(InputType.TYPE_NULL);

这里要对EditText输入框注册onTouchListener ,而不能使用onClickListener ;因为注册onClickListener时会有这样一个现象:当EditText第一次获得焦点时,不能弹出对话框。只有在EditText已经获得焦点的情况下,再次点击才能弹出对话框


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP