Java 软键盘切断了EditText/TextInputText控件的底部
我正在经历下图所示的挑战 我唯一没有遇到这种挑战的时候是EditText控件没有用于实现控件周围边界的drawable 我尝试了以下建议,似乎可以解决它 建议1Java 软键盘切断了EditText/TextInputText控件的底部,java,android,android-layout,android-softkeyboard,Java,Android,Android Layout,Android Softkeyboard,我正在经历下图所示的挑战 我唯一没有遇到这种挑战的时候是EditText控件没有用于实现控件周围边界的drawable 我尝试了以下建议,似乎可以解决它 建议1 @Override //public void setBackground(Drawable background) { public void setBackgroundResource(int resid) { int pl = getPaddingLeft(); int pt = getPaddingTop(
@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
@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);
}
我布局的一部分
<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>
@尺寸/文本视图高度
@尺寸/文本视图
@尺寸/文本视图底部填充
@可绘制/选择器\文本\控件\编辑
真的
无衬线
中心垂直
1.
真的
@颜色/控制文本颜色
@颜色/控件文本视图提示
@可绘制/光标
真的
@尺寸/控制文本尺寸
解决方案
我已经为EditText/TextInputText控件设置了固定高度。我将其从
android:layout\u height='48dp'
更改为android:layout\u height='match\u content'
添加到您的活动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>
您应该将父布局用作
RelativeLayout
然后在你的文本输入文本中添加android:layout\u alignParentBottom=“true”
,如下所示
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:hint="username ">
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<android.support.design.widget.TextInputEditText
android:id="@+id/txtUserName"
style="@style/EditTextViewSingleRowStyle"
android:layout_width="match_parent"
android:layout_height="46dp"
android:background="@drawable/edittextBorder"
android:layout_marginBottom="10dp"
android:inputType="text"
android:nextFocusDown="@+id/txtPassword"
android:nextFocusLeft="@id/txtUserName"
android:nextFocusRight="@+id/txtPassword"
android:nextFocusUp="@id/txtUserName" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
然后像这样输出
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:hint="username ">
<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<android.support.design.widget.TextInputEditText
android:id="@+id/txtUserName"
style="@style/EditTextViewSingleRowStyle"
android:layout_width="match_parent"
android:layout_height="46dp"
android:background="@drawable/edittextBorder"
android:layout_marginBottom="10dp"
android:inputType="text"
android:nextFocusDown="@+id/txtPassword"
android:nextFocusLeft="@id/txtUserName"
android:nextFocusRight="@+id/txtPassword"
android:nextFocusUp="@id/txtUserName" />
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
我已经为EditText/textinputtext控件设置了一个固定的高度。我将其从android:layout\u height='48dp'
更改为android:layout\u height='match\u content'
您是否尝试过将Scrollview
作为您版面中的家长发布您的xml?这取决于您的xml文件中包含的内容。我的意思是布局类型,视图对齐和其他东西@Tebo@vikassingh我已经尝试了ScrollView
@Tebo你能试试我的答案吗你确定它与android:layout\u height=“46dp”
一起工作对我来说这就是问题所在。我会稍后测试你的答案,如果有效,我会投票支持。android中没有匹配内容。是的,我通过了,我明白了。后来改变了。
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:height="5dp" />
<padding
android:bottom="15dp"
android:top="15dp" />
<!-- Background Color -->
<solid android:color="#f2f1f1" />
<!-- Border Color -->
<stroke
android:width="2dp"
android:color="#b90917" />
<!-- Round Corners -->
<corners android:radius="5dp" />
</shape>