我遇到了下图所示的挑战;
唯一一次我没有遇到这个挑战是当 EditText 控件没有用于实现控件周围边框的可绘制对象时。
我已经尝试了以下建议,但似乎无法修复它;
建议1
@Override
//public void setBackground(Drawable background) {
public void setBackgroundResource(int resid) {
int pl = getPaddingLeft();
int pt = getPaddingTop();
int pr = getPaddingRight();
int pb = getPaddingBottom();
super.setBackgroundResource(resid);
this.setPadding(pl, pt, pr, pb);
}
建议2
android:windowSoftInputMode="adjustResize"
建议3
android:windowSoftInputMode="adjustPan"
如何让 EditText 控件位于软键盘周围?
更新1
我的布局的一部分;
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint=" "
>
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="0px"
android:layout_height="0px"/>
<android.support.design.widget.TextInputEditText
android:id="@+id/txtUserName"
android:layout_width="match_parent"
android:layout_marginBottom="@dimen/textControlMarginBottom"
android:hint="@string/userNameHint"
android:inputType="text"
android:nextFocusUp="@id/txtUserName"
android:nextFocusLeft="@id/txtUserName"
android:nextFocusDown="@+id/txtPassword"
android:nextFocusRight="@+id/txtPassword"
style="@style/EditTextViewSingleRowStyle" />
</android.support.design.widget.TextInputLayout>
<小时/>
<style name="EditTextViewSingleRowStyle">
<item name="android:layout_height">@dimen/textViewHeight</item>
<item name="android:paddingTop">@dimen/textViewTopPadding</item>
<item name="android:paddingBottom">@dimen/textViewBottomPadding</item>
<item name="android:background">@drawable/selector_text_control_edit</item>
<item name="android:cursorVisible">true</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:gravity">center_vertical</item>
<item name="android:maxLines">1</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">@color/controlTextColor</item>
<item name="android:textColorHint">@color/controlTextViewHint</item>
<item name="android:textCursorDrawable">@drawable/cursor</item>
<item name="android:textIsSelectable">true</item>
<item name="android:textSize">@dimen/controlTextSize</item>
</style>
解决方案
我为 EditText/TextInputEditText 控件设置了固定高度。我将其从 android:layout_height='48dp'
更改为 android:layout_height='match_content'
最佳答案
添加到您的 Activity ScrollView
:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ScrollView>
然后在您的 activity
中确保您正在执行类似的操作(此代码只是为了演示在哪里使用
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);)
例如:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
final EditText edittext= (EditText)findViewById(R.id.edittext1);
edittext.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
edittext.requestLayout();
MyActivity.this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
return false;
}
});
}
关于java - 软键盘切断了我的 EditText/TextInputEditText 控件的底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48402945/