Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CoordinatorLayout messing up setError popup position

I'm facing an issue with EditText setError popup position.

Edit Text Error

I'm using the following code in to create the layout:

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>

profile.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>

What I have tried

If I change the android.support.design.widget.CoordinatorLayout with LinearLayout the setError issue won't happen, but that will change the status bar color to white one and my UI is looking odd.

Corrected, status bar issue

I'm new to Android programming and not sure what's going on, please help me.

like image 570
Midhun MP Avatar asked Nov 09 '15 11:11

Midhun MP


1 Answers

What worked for me is an extra LinearLayout in activity_main.xml (yes, there):

<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>

This also works around the layout bug that shows when you toggle visibility of a view in a fragment.

And the next problem is white-on-white error messages in the popup on Android 2.x (link)

like image 125
18446744073709551615 Avatar answered Sep 22 '22 00:09

18446744073709551615