gpt4 book ai didi

android - CoordinatorLayout 弄乱了 setError 弹出位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:59:52 27 4
gpt4 key购买 nike

我遇到了 EditText setError 弹出位置的问题。

Edit Text Error

我正在使用以下代码来创建布局:

activity_profile.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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" android:fitsSystemWindows="true"
tools:context=".ProfileActivity"
android:orientation="vertical">

<android.support.design.widget.AppBarLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/profile" />

</android.support.design.widget.CoordinatorLayout>

配置文件.xml

<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".ProfileActivity"
tools:showIn="@layout/activity_profile">

<EditText
android:id="@+id/etProfileName"
android:layout_width="match_parent"
android:layout_height="50dp"
android:capitalize="words"
android:hint="@string/et_hint_profile_name"
android:textAlignment="center" />
</RelativeLayout>

我尝试过的

如果我将 android.support.design.widget.CoordinatorLayout 更改为 LinearLayout,则不会发生 setError 问题,但那会将状态栏颜色更改为白色,我的 UI 看起来很奇怪。

Corrected, status bar issue

我是 Android 编程的新手,不确定发生了什么,请帮助我。

最佳答案

对我有用的是 activity_main.xml 中的额外 LinearLayout(是的,有):

<android.support.design.widget.CoordinatorLayout
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:id="@+id/activityRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.example.biptest.MainActivity">

<!-- *** THIS ONE *** -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appbar"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" /> <!-- FRAGMENT(S) INSIDE -->

</LinearLayout>
<!-- *** BUT LEAVE THE FAB ALONE *** -->

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email"
android:visibility="gone"
/>

</android.support.design.widget.CoordinatorLayout>

这也解决了当您切换 fragment 中 View 的可见性时显示的布局错误。

下一个问题是 Android 2.x (link) 上弹出窗口中的白色错误消息

关于android - CoordinatorLayout 弄乱了 setError 弹出位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33608564/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com