我正在尝试使用“编辑文本”字段进行布局以处理电子邮件请求。该设计使键盘始终在editText视图上打开,从而使您无法知道所输入的内容。我已经尝试了很多关于堆栈溢出的建议,但是大多数建议都是针对API <24的(尽管我认为这对此没有太大影响)。
在“活动”文件中,我尝试了以下操作:
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
在Android清单中,我还结合或单独尝试了以下方法:
android:windowSoftInputMode="adjustPan"
android:windowSoftInputMode="stateHidden|adjustPan"
android:windowSoftInputMode="adjustResize"
我还按照Heena的描述将布局包裹在ScrollView中 此处:https://stackoverflow.com/a/39867438/5635144
下面是我的XML及其伴随的活动
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="match_parent"
tools:context=".EmailResetActivity">
<RelativeLayout
android:id="@+id/bg"
android:layout_width="match_parent"
android:layout_height="419dp"
android:background="@drawable/signin_up_anim"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
...
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
<EditText
android:id="@+id/e_request"
android:layout_width="305dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="8dp"
android:ems="10"
android:hint="@string/email_address"
android:inputType="textEmailAddress"
android:paddingStart="10dp"
android:paddingBottom="15dp"
android:textColorHint="@color/hintgrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.522"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/bg" />
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/buttonsContainer"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/e_request">
<Button
android:id="@+id/sendRequestBtn"
android:layout_width="150dp"
android:layout_height="45dp"
android:background="@drawable/large_btn"
android:text="@string/submit"
android:textColor="@color/white" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
class EmailResetActivity : AppCompatActivity() {
lateinit private var auth: FirebaseAuth
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_email_reset)
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN or WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
auth = FirebaseAuth.getInstance()
val animDrawable = resetPassInfoBg.background as AnimationDrawable
animDrawable.setEnterFadeDuration(2500)
animDrawable.setExitFadeDuration(1500)
animDrawable.start()
sendRequestBtn.setOnClickListener(View.OnClickListener {
val email = e_request.getText().toString().trim()
if (TextUtils.isEmpty(email)) {
Toast.makeText(application, "Enter your email ", Toast.LENGTH_SHORT).show()
return@OnClickListener
}
})
}
}
我希望将布局向上移动,以使editText字段可见,但目前没有任何方法使它起作用。
答案 0 :(得分:1)
Remove this line:
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
With FLAG_LAYOUT_NO_LIMITS
the application is not able to calculate how to scroll your view, because your layout has no limits.