我有一个多行的EditText,下面有一个提交按钮。
当用户点击EditText区域时,软键盘出现
它上面有一个回车键,用户可以移动到下一行
我的问题是软键盘隐藏了我的提交按钮-因此,当用户完成编辑时,他/她必须按下设备上的后退按钮来隐藏软键盘以提交
有没有什么方法可以同时保持键盘上的回车键和完成键?或者,还有其他更好的解决方案吗?
提前谢谢。
是的,您可以使用按钮始终位于页面底部但位于键盘顶部的布局,像这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/button_save"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:enabled="false"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:text="@string/button_save" />
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="@+id/button_save"
android:fadeScrollbars="false"
>
...all your stuff here
</ScrollView>
</RelativeLayout>
您还可以在xml布局中设置imeAction
,这将允许您直接从软键盘调用Done/Next/Search等,只要您的editText有这些事件的侦听器。