How to add margin between EditText and Soft Keyboard?(如何在 EditText 和软键盘之间添加边距?)
问题描述
我想在 EditText 和软键盘之间添加 10dp 的边距.
I want to add 10dp margin between EditText and Soft Keyboard.
这是我的 XML:
<RelativeLayout
android:id="@+id/BottomLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/bottom_glass" >
<EditText
android:id="@+id/message"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/grey"
android:ems="10"
android:layout_marginBottom="10dp"
android:hint="Enter Message"
android:textColor="#ffffff" >
</EditText>
<ImageButton
android:id="@+id/sendMessageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="20dp"
android:layout_toRightOf="@+id/message"
android:background="@android:color/transparent"
android:src="@drawable/sendselector" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:layout_toLeftOf="@+id/message"
android:background="@android:color/transparent"
android:src="@drawable/sendmediaselector" />
</RelativeLayout>
这是我的 onCreate()
:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
messageText.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
((Swipe)getActivity()).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}});
我正在使用 viewpager 和全屏主题.以下 EditText 在我的第三个片段中.
I am using viewpager and full screen theme. The following EditText is in my 3rd fragment.
我使用了 android:windowSoftInputMode="adjustResize|adjustPan"
和 android:windowSoftInputMode="adjustResize"
,但什么也没发生.
I've used android:windowSoftInputMode="adjustResize|adjustPan"
and android:windowSoftInputMode="adjustResize"
, but nothing happened.
推荐答案
我发现paddingBottom
的属性会影响editText
和键盘的距离.你可以这样做:
I find the attribute of paddingBottom
can effect the distance between the editText
and the keyboard. You can do like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="110dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@drawable/your_edit_text_background"/>
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"/>
</RelativeLayout>
这将使您的键盘边距 EditText
10dp
This will make your keyboard margin your EditText
by 10dp
这篇关于如何在 EditText 和软键盘之间添加边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 EditText 和软键盘之间添加边距?


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01