如何强制软键盘不在 edittext 下隐藏 textview/counter?
How to force soft-keyboard NOT to hide textview/counter under edittext?
问题是 android 键盘在打开时将 textview 隐藏在 edittext 下(不是 edittext 本身!)。
这是我的布局示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/big_image"
android:layout_width="200dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:src="@drawable/ic_launcher_foreground"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/comment_input_layout"
android:text="0/250"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
下图清楚:
screen without keyboard
actual behavior
expected behavior
我在Whosebug上发现了几个类似的问题,其中none个都有解决方案:(
请帮我解决这个问题!
可以肯定的是,考虑到 android:windowSoftInputMode="adjustPan"
,我使用了所有建议
或 android:windowSoftInputMode="adjustResize"
或 android:focusableInTouchMode="true"
或 android:fitsSystemWindows="true"
或将此 textview 添加到与 edittext 布局分开的位置,将 framelayout 作为根,
不过问题有点复杂
另一件重要的事情是,编辑文本下面的 文本应该
当文本在另一行时保持在键盘上方
编辑文本向上滚动时消失(因为它是编辑文本的一部分)。
请将此 app:counterEnabled="true
" app:counterMaxLength="250"
添加到您的 TextInputLayout
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
app:counterEnabled="true"
app:counterMaxLength="250"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
编辑:
请在您的清单中尝试此操作
android:windowSoftInputMode="stateVisible|adjustResize"
您也可以使用此设计存档您的设计
在 XML 中使用 TextInputLayout 编辑文本
<android.support.design.widget.TextInputLayout
android:id="@+id/itFAuthAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
app:passwordToggleEnabled="true"
app:counterEnabled="true"// add this
app:counterMaxLength="250" //add this
app:hintTextAppearance="@style/AppTextInputHintLabelStyle">
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/et_auth_f_que_hint"
android:imeOptions="actionDone"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
这行代码以不同的方式解决了您的问题,也适合您当前的设计。
app:counterEnabled="true"// make it true
app:counterMaxLength="250"//set your limit
快乐学习...
我遇到了同样的问题。关于这个,我已经 log a ticket 到 Material。
我申请的 "hack" 是这样的,感谢我很棒的同事的建议:
每当呈现布局并且我单击具有计数器的字段(这是我布局中的最后一个字段)时,以编程方式将其滚动到底部,以便键盘不再隐藏计数器。
下面是我的程序的不同部分代码,你可以参考一下:
override fun onFocusChange(p0: View?, isOnFocus: Boolean) {
if (isOnFocus.not() && getDescription().isEmpty()) {
tnDescriptionLayout.error = resources.getString(R.string.description_error_message)
tnDescriptionLayout.isErrorEnabled = true
} else {
tnDescriptionLayout.isErrorEnabled = false
llayout.postDelayed(object : Runnable {
override fun run() {
var v =
tnDescriptionLayout.findViewById<AppCompatTextView>(R.id.textinput_counter)
nestedScrollView.smoothScrollBy(0,v.height)
}
}, CoreConstants.MINIMUM_VIEW_LOAD_DURATION)
}
tvDescription.setText(getDescription())
lateinit var nestedScrollView: NestedScrollView
fun change(nestedScrollView: NestedScrollView){
this.nestedScrollView=nestedScrollView
}
paymentOrderContent.change(nestedScrollView = parentView.nestedScrollViewParent)
希望对您有所帮助!
问题是 android 键盘在打开时将 textview 隐藏在 edittext 下(不是 edittext 本身!)。
这是我的布局示例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/big_image"
android:layout_width="200dp"
android:layout_height="600dp"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:src="@drawable/ic_launcher_foreground"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
</android.support.design.widget.TextInputLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/comment_input_layout"
android:text="0/250"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
下图清楚:
screen without keyboard
actual behavior
expected behavior
我在Whosebug上发现了几个类似的问题,其中none个都有解决方案:(
请帮我解决这个问题!
可以肯定的是,考虑到 android:windowSoftInputMode="adjustPan"
,我使用了所有建议
或 android:windowSoftInputMode="adjustResize"
或 android:focusableInTouchMode="true"
或 android:fitsSystemWindows="true"
或将此 textview 添加到与 edittext 布局分开的位置,将 framelayout 作为根,
不过问题有点复杂
另一件重要的事情是,编辑文本下面的 文本应该
当文本在另一行时保持在键盘上方
编辑文本向上滚动时消失(因为它是编辑文本的一部分)。
请将此 app:counterEnabled="true
" app:counterMaxLength="250"
添加到您的 TextInputLayout
<android.support.design.widget.TextInputLayout
android:id="@+id/comment_input_layout"
android:layout_width="match_parent"
app:counterEnabled="true"
app:counterMaxLength="250"
android:layout_height="wrap_content"
android:layout_below="@+id/big_image">
<EditText
android:id="@+id/comment_edittext_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="your comment"
android:imeOptions="actionDone"
android:maxLength="250"/>
编辑:
请在您的清单中尝试此操作
android:windowSoftInputMode="stateVisible|adjustResize"
您也可以使用此设计存档您的设计
在 XML 中使用 TextInputLayout 编辑文本
<android.support.design.widget.TextInputLayout
android:id="@+id/itFAuthAnswer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_5sdp"
app:passwordToggleEnabled="true"
app:counterEnabled="true"// add this
app:counterMaxLength="250" //add this
app:hintTextAppearance="@style/AppTextInputHintLabelStyle">
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/et_auth_f_que_hint"
android:imeOptions="actionDone"
android:singleLine="true"/>
</android.support.design.widget.TextInputLayout>
这行代码以不同的方式解决了您的问题,也适合您当前的设计。
app:counterEnabled="true"// make it true
app:counterMaxLength="250"//set your limit
快乐学习...
我遇到了同样的问题。关于这个,我已经 log a ticket 到 Material。 我申请的 "hack" 是这样的,感谢我很棒的同事的建议: 每当呈现布局并且我单击具有计数器的字段(这是我布局中的最后一个字段)时,以编程方式将其滚动到底部,以便键盘不再隐藏计数器。
下面是我的程序的不同部分代码,你可以参考一下:
override fun onFocusChange(p0: View?, isOnFocus: Boolean) {
if (isOnFocus.not() && getDescription().isEmpty()) {
tnDescriptionLayout.error = resources.getString(R.string.description_error_message)
tnDescriptionLayout.isErrorEnabled = true
} else {
tnDescriptionLayout.isErrorEnabled = false
llayout.postDelayed(object : Runnable {
override fun run() {
var v =
tnDescriptionLayout.findViewById<AppCompatTextView>(R.id.textinput_counter)
nestedScrollView.smoothScrollBy(0,v.height)
}
}, CoreConstants.MINIMUM_VIEW_LOAD_DURATION)
}
tvDescription.setText(getDescription())
lateinit var nestedScrollView: NestedScrollView
fun change(nestedScrollView: NestedScrollView){
this.nestedScrollView=nestedScrollView
}
paymentOrderContent.change(nestedScrollView = parentView.nestedScrollViewParent)
希望对您有所帮助!