【问题标题】:EditText not showing, typing text on Bottom sheet dialogEditText 未显示,在底部工作表对话框中输入文本
【发布时间】:2020-04-24 19:24:23
【问题描述】:

在底部工作表对话框中,我们有一些编辑文本的 .输入这些edittext时可以输入,但输入后没有显示输入文本也没有显示edittext光标。

当屏幕触摸/滚动编辑文本正在更新时。我认为这是我的设计问题。请看一下我的 xml。

当键盘突出显示时,计时器也会停止。我也试过runOnUiThread,它不工作。

<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/rlBottomSheet"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <!-- Swipe down -->
        <LinearLayout
            android:id="@+id/llSwipeDown"
            android:backgroundTint="@color/colorTransparent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:padding="@dimen/dimen_30dp"
                android:textColor="@color/white"
                android:text="@string/swipe_down_to_cancel" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/llSwipeDown"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:background="@drawable/bottom_sheet_background_shape"
                android:gravity="center"
                android:paddingStart="@dimen/dimen_8dp"
                android:paddingEnd="@dimen/dimen_8dp"
                android:orientation="horizontal"
                android:paddingTop="@dimen/dimen_20dp"
                android:paddingBottom="@dimen/dimen_20dp">

                <ImageView
                    android:layout_width="@dimen/dimen_0dp"
                    android:layout_height="@dimen/dimen_30dp"
                    android:layout_weight=".10"
                    android:contentDescription="@string/_dummy"
                    android:src="@drawable/ic_" />

                <TextView
                    android:id="@+id/tvUserName"
                    android:layout_width="@dimen/dimen_0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="@dimen/dimen_10dp"
                    android:layout_weight="1"
                    android:ellipsize="marquee"
                    android:fontFamily="@font/opensans_semibold"
                    android:gravity="start|center"
                    android:singleLine="true"
                    android:text=""
                    android:textColor="@color/white"
                    android:textSize="18sp" />

                <Chronometer
                    android:id="@+id/chTimer"
                    android:layout_width="@dimen/dimen_0dp"
                    android:layout_height="match_parent"
                    android:layout_gravity="end"
                    android:layout_weight=".2"
                    android:fontFamily="@font/opensans_regular"
                    android:gravity="center"
                    android:text="11.05"
                    android:textColor="@color/white" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:gravity="center"
                android:background="@color/white"
                android:orientation="vertical">

                <com.google.android.material.textfield.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:layout_weight="1"
                    android:hint="@string/str_hint_product_name">

                    <com.google.android.material.textfield.TextInputEditText
                        android:id="@+id/tvName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Test Product 1"
                        android:textColor="@color/black"
                        android:textColorHint="@color/cardview_shadow_start_color"
                        android:textSize="16sp">

                    </com.google.android.material.textfield.TextInputEditText>
                </com.google.android.material.textfield.TextInputLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:orientation="horizontal">

                    <com.google.android.material.textfield.TextInputLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:hint="@string/str_hint_id">

                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/tvId"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:singleLine="true"
                            android:text="Test Product 123"
                            android:textColor="@color/black"
                            android:textColorHint="@color/cardview_shadow_start_color"
                            android:textSize="16sp">

                        </com.google.android.material.textfield.TextInputEditText>
                    </com.google.android.material.textfield.TextInputLayout>

                    <ImageView
                        android:id="@+id/iv"
                        android:layout_width="@dimen/dimen_25dp"
                        android:layout_height="@dimen/dimen_25dp"
                        android:layout_gravity="center"
                        android:background="@drawable/ic_code"
                        android:backgroundTint="@color/cardview_shadow_start_color"
                        android:contentDescription="@string/iv_" />
                </LinearLayout>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/rvImages"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </androidx.recyclerview.widget.RecyclerView>


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:orientation="horizontal">

                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.5">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/str_price"
                            android:textSize="@dimen/dimen_18sp" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center|start">

                        <TextView
                            android:id="@+id/tvPriceDot"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/dimen_10dp"
                            android:text=""
                            android:textSize="@dimen/dimen_18sp" />

                        <EditText
                            android:id="@+id/etPrice"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_toEndOf="@+id/tvPriceDot"
                            android:importantForAutofill="no"
                            android:inputType="number"
                            android:singleLine="true"
                            android:text="1000"
                            android:drawableStart="@drawable/rupee_symbol" />
                    </RelativeLayout>


                </LinearLayout>


                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:baselineAligned="false"
                    android:orientation="horizontal">

                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:gravity="center|start">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="@string/str_quantity"
                            android:textSize="@dimen/dimen_18sp" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center|start">

                        <TextView
                            android:id="@+id/tvQDot"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/dimen_10dp"
                            android:text="@string/str_colon"
                            android:textSize="@dimen/dimen_18sp" />

                        <ImageButton
                            android:id="@+id/ibQRemove"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/dimen_10dp"
                            android:layout_toEndOf="@+id/tvQDot"
                            android:background="@drawable/border_background"
                            android:contentDescription="@string/ibremove"
                            android:src="@drawable/ic_action_remove" />

                        <TextView
                            android:id="@+id/tvQCount"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_marginTop="@dimen/dimen_10dp"
                            android:layout_toEndOf="@+id/ibQRemove"
                            android:background="@drawable/border_background"
                            android:padding="@dimen/dimen_3dp"
                            android:paddingStart="@dimen/dimen_20dp"
                            android:paddingEnd="@dimen/dimen_20dp"
                            android:text="1" />

                        <ImageButton
                            android:id="@+id/ibQAdd"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/dimen_10dp"
                            android:layout_toEndOf="@+id/tvQuantityCount"
                            android:background="@drawable/border_background"
                            android:contentDescription="@string/ib_quantity_add"
                            android:src="@drawable/ic_action_add" />
                    </RelativeLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:orientation="horizontal"
                    android:visibility="gone">
                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.5"
                        android:gravity="center|start">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text=""
                            android:textSize="@dimen/dimen_18sp" />
                    </RelativeLayout>

                    <RelativeLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:gravity="center|start">

                        <TextView
                            android:id="@+id/tvDot"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/dimen_10dp"
                            android:text="@string/str_colon"
                            android:textSize="@dimen/dimen_18sp" />

                        <EditText
                            android:id="@+id/et"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_toEndOf="@+id/tvDot"
                            android:importantForAutofill="no"
                            android:inputType="number"
                            android:text="0"
                            android:singleLine="true" />
                    </RelativeLayout>
                </LinearLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dimen_2dp"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:background="@color/colorBottomSheetLineSeparator" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/dimen_10dp"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btnCancel"
                        style="@style/Widget.AppCompat.Button.Borderless"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="@string/str_cancel"
                        android:textAllCaps="false" />

                    <Button
                        android:id="@+id/btnSend"
                        style="@style/Widget.AppCompat.Button"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:background="@drawable/send_button_corner_radius"
                        android:text="@string/str_send"
                        android:textAllCaps="false"
                        android:textColor="@color/white" />

                </LinearLayout>

            </LinearLayout>

        </LinearLayout>

    </RelativeLayout>

【问题讨论】:

  • 您应该尝试使您的布局文件更短一些。您可以将某些部分提取到另一个布局文件中,并使用 include 标签在您的主布局文件中使用它们。
  • 好的。谢谢你的评论
  • 感谢@Ezio。我只是按照你说的试过了,还去掉了所有的重量。现在它的工作。但是发现了更多的延迟,但我可以在 edittext 上显示输入文本。
  • 什么时候出现延迟?
  • 当键盘高亮输入时。但是我们总共有3个edittext,最后一个有问题

标签: android android-edittext bottom-sheet chronometer android-bottomsheetdialog


【解决方案1】:

希望这会帮助你.. 请在 Manifest 中更新此内容。android:windowSoftInputMode="adjustPan" 在 Edittext 中单击时向上移动...

【讨论】:

  • 除了相对和约束,使用约束以获得更好的性能..
  • 在 Manifest 中,已尝试但无法正常工作。向上移动???
【解决方案2】:

就我而言,这是因为我的 android:hardwareAccelerated="false"

确保在您的 AndroidManifest.xml 中,您的硬件加速是真实的。

代码:

android:hardwareAccelerated="true"

【讨论】:

    【解决方案3】:

    在返回视图之前在onCreateView中添加dialog!!.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)

    以下是该方法的完整代码

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? {
            binding = DataBindingUtil.inflate(
                inflater,
                R.layout.layout_password_dialog,
                container,
                false
            )
            dialog!!.window!!.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
            return binding.root
        }
    

    look her for details

    【讨论】:

      猜你喜欢
      • 2020-12-11
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2016-06-21
      • 2014-06-14
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      相关资源
      最近更新 更多