【发布时间】:2017-05-13 08:54:10
【问题描述】:
在调用editText.setError("...") 时,我的EditText 的错误指示器的位置出现问题。
正如您在屏幕截图中看到的那样,我使用的是BottomSheetDialog,其中包含EditText。当我显示错误指示器时,文本完全不合适。对话框似乎“认为”它是全屏的,但实际上并非如此。
这是我的对话框布局文件(phone_dialog.xml):
<android.support.constraint.ConstraintLayout 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="wrap_content"
android:layout_weight="0"
android:orientation="vertical">
<TextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:padding="@dimen/padding_layout_normal"
android:text="@string/dialog_title_edit_phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<EditText
android:id="@+id/etPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center"
android:inputType="phone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvTitle"/>
<Button
android:id="@+id/btnSavePhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/etPhone"/>
</android.support.constraint.ConstraintLayout>
我的Activity 布局文件(activity_contacts.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContacts"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
这就是我在Activity 中显示对话框的方式:
PhoneBottomDialog dialog = new PhoneBottomDialog(Context);
dialog.show();
这是我的PhoneBottomDialog 班级:
public class PhoneBottomDialog extends BottomSheetDialog {
public PhoneBottomDialog(Context context) {
super(context);
View view = getLayoutInflater().inflate(R.layout.phone_dialog, null);
setContentView(view);
// additional setup below this...
}
// ...
}
我没有在我的自定义 PhoneButtomDialog 中执行任何其他布局。将我的对话框的根布局更改为RelativeLayout 或LinearLayout 以及添加ScrollView 并没有改变任何东西。这也不是与设备或特定 Android 版本相关的问题,因为该问题出现在从 Android 5.0 到 7.1 的所有测试设备上,它也出现在模拟器上。
有人知道为什么会这样吗?
【问题讨论】:
-
尝试任何其他根布局而不是
-
感谢您的建议,刚刚用
RelativeLayout尝试过,不幸的是同样的问题。 -
尝试将编辑文本包装在 TextInputLayout 中
-
谢谢,我试过了,但还是有同样的问题。
-
我已将活动布局精简到最低限度,仅包含
RecyclerView和LinearLayout,问题仍然存在。
标签: android android-layout dialog android-edittext bottom-sheet