首页 > 其他 > 详细

怎么设置软键盘中Enter的监听

时间:2014-12-03 17:10:43      阅读:244      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

/**布局中必须设置属性<singleLine & imeOptions>*/
<EditText                
android:id="@+id/edt_searchMicroFilm"                
android:layout_width="fill_parent"               
 android:layout_height="32dp"                
android:layout_marginRight="10dp"               
 android:background="@drawable/search_frame_shape_circle"               
 android:gravity="center_vertical"                
android:hint="@string/plaseInputKeyWords"               
 android:paddingLeft="25dp"                
android:textColorHighlight="@color/jxInputFrameHintTextColor"               
 android:textColor="@color/jxTitleTextWord"               
 android:imeOptions="actionSearch"               
 android:singleLine="true"                
android:textSize="14sp" >           
 </EditText>
/**在Activity类中编写自己的功能代码,即设置监听事件:*/
editText.setOnEditorActionListene( newTextView.OnEditorActionListener() { 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event){ 
if (actionId == EditorInfo.IME_ACTION_SEARCH ||(event!=null && event.getKeyCode()== KeyEvent.KEYCODE_ENTER)) { 
// 在这里编写自己想要实现的功能                           
   ..... return true;                          
}                          
 return false;<pre name="code" class="java">         }   }); 


我想你既然来到这里看这篇文章至少是想要了解怎么去重新设置手机弹出的软键盘上Enter功能。使得点击过Enter键之后,响应自己想要实现的功能。而软件盘的界面替换却有这么一个属性android:imeOptions来满足我们的需要,这个属性的可以取的值有normalactionUnspecifiedactionNoneactionGoactionSearchactionSendactionNextactionDone,例如:当值为actionNextenter键外观变成一个向下箭头;当值为actionSearch时候Enter键外观变成搜索两个字;而值为actionDoneenter键外观则变成了完成两个字。

在进行自己自定义的响应的功能设置时候,要注意<下面三条必须的满足>

1.XML布局中设置其属性android:imeOptions,如上图;

2.XML布局中设置其属性android:singleLine="true",保证点击Enter键时,能被正确监听到;

3.在代码中设置监听:editText.setOnEditorActionListene();并完成自己想要实现的功能代码;




怎么设置软键盘中Enter的监听

原文:http://blog.csdn.net/junhuahouse/article/details/41698785

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!