本文介绍了如何在Android的软键盘上粘贴EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试制作下图所示的图像,其中在活动开始并且EditText
和发送按钮固定在键盘上时,键盘会自动打开.
I'm trying to make something like the image below, where the keyboard automatically opens when the activity starts and the EditText
and the send button stick to the keyboard.
推荐答案
使用以下代码在活动启动时自动弹出软键盘
Use the below code to pop up the soft keyboard automatically when an activity launches
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(youredittext, 0);
确保未在manifest.xml中定义android:windowSoftInputMode="stateHidden"
.
Make sure that you have not define android:windowSoftInputMode="stateHidden"
in your manifest.xml.
要使用页脚附加Edittext,请使用以下代码:
To make an Edittext attach with the footer,use the following code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f3f3f3"
android:paddingBottom="10.0dip"
android:paddingTop="10.0dip"
android:id="@+id/bottom_bar" >
<EditText
android:id="@+id/et_send_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10.0dip"
android:layout_toLeftOf="@+id/ib_send"
android:hint="Enter Message"
android:singleLine="true" />
<ImageView
android:id="@+id/ib_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/et_send_bar"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/et_send_bar"
android:layout_marginBottom="1px"
android:layout_marginRight="10.0dip"
android:layout_marginTop="1px"
android:background="@drawable/chatsend_bg"
android:paddingBottom="5.0dip"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5.0dip"
android:src="@drawable/ic_send_dark_normal" />
</RelativeLayout>
这篇关于如何在Android的软键盘上粘贴EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!