Pun*_*nit 28 android android-keypad android-edittext android-fragments android-viewpager
我想在EditText和Soft Keyboard之间添加10dp的边距.
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的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;
}});
Run Code Online (Sandbox Code Playgroud)
我正在使用viewpager和全屏主题.以下EditText位于我的第3个片段中.
我用android:windowSoftInputMode="adjustResize|adjustPan"和android:windowSoftInputMode="adjustResize",但什么都没有发生.
小智 15
我发现paddingBottom可以影响editText键盘和键盘之间距离的属性.你可以这样做:
<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>
Run Code Online (Sandbox Code Playgroud)
这将使你的键盘保证金您EditText通过10dp
这似乎有效,但对布局有一些不必要的影响。
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
Run Code Online (Sandbox Code Playgroud)
如果有人知道如何让它与 ADJUST_PAN 一起工作,那就太好了!