EditText字段中包含错误文本的Android问题

时间:2016-03-30 11:08:43

标签: android

我的EditText字段存在以下问题,其中errortext未正确显示。感觉它被包裹在一个边界内。我甚至试图增加父布局的高度,但结果仍然相同。

enter image description here

我的布局定义如下:

<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"
tools:context="com.devinedesign.cleanride.activities.SignUpActivity">

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="50dp">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#0071bb"
        android:gravity="center_vertical">

        <ImageView
            android:layout_width="30dp"
            android:layout_height="20dp"
            android:id="@+id/backButtonImageView"
            android:src="@drawable/left_arrow_icon"
            android:layout_marginLeft="20dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Sign Up"
            android:id="@+id/textView33"
            android:textColor="#FFFFFF"
            android:layout_marginLeft="10dp"
            android:textSize="24sp" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:weightSum="1"
    android:paddingLeft="10dp"
    android:paddingRight="10dp">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal|clip_vertical"
        android:layout_marginTop="10dp">

        <ImageView
            android:layout_width="210dp"
            android:layout_height="70dp"
            android:id="@+id/imageView3"
            android:layout_gravity="center_horizontal"
            android:background="@drawable/logo_and_text" />
    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="2dp"
                android:gravity="center_vertical|center_horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="20dp"
                    android:id="@+id/imageView18"
                    android:src="@drawable/login_email_icon"
                    android:layout_marginLeft="10dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/sgnEmailTxt"
                    android:hint="Email ID"
                    android:imeOptions="actionNext"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:theme="@style/CleanRideEditText"/>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_vertical|center_horizontal">

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="20dp"
                    android:id="@+id/imageView20"
                    android:src="@drawable/login_key_icon"
                    android:layout_marginLeft="10dp" />

                <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:inputType="textPassword"
                    android:ems="10"
                    android:id="@+id/sgnPasswordTxt"
                    android:layout_marginLeft="20dp"
                    android:hint="Password"
                    android:theme="@style/CleanRideEditText"/>

            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_vertical|center_horizontal" >

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="20dp"
                    android:id="@+id/imageView16"
                    android:src="@drawable/name_icon"
                    android:layout_marginLeft="10dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/sgnNameTxt"
                    android:hint="Full Name"
                    android:imeOptions="actionNext"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:theme="@style/CleanRideEditText"/>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_vertical|center_horizontal" >

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="20dp"
                    android:id="@+id/imageView17"
                    android:src="@drawable/mobile_icon"
                    android:layout_marginLeft="10dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/sgnPhoneNoTxt"
                    android:hint="Phone No"
                    android:imeOptions="actionNext"
                    android:inputType="number"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:maxLength="13"
                    android:theme="@style/CleanRideEditText"/>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_vertical|center_horizontal" >

                <ImageView
                    android:layout_width="40dp"
                    android:layout_height="20dp"
                    android:id="@+id/imageView21"
                    android:src="@drawable/referral_icon"
                    android:layout_marginLeft="10dp" />

                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/sgnReferralCodeTxt"
                    android:hint="Referral Code"
                    android:imeOptions="actionDone"
                    android:inputType="number"
                    android:layout_marginLeft="20dp"
                    android:singleLine="true"
                    android:theme="@style/CleanRideEditText"/>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="12dp">

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SIGN UP"
            android:id="@+id/signUpButton"
            android:background="@drawable/clean_ride_button_selector"
            android:textColor="#FFFFFF"

            android:elevation="2dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp" />
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"
        android:gravity="center_vertical|center_horizontal">

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="100dp"
            android:layout_height="1dp"
            android:clickable="true"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal" >
            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:id="@+id/lseparator"
                android:scaleType="fitXY"
                android:background="#000000"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="5dp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:orientation="horizontal"
            android:gravity="center_vertical|center_horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="or"
                android:id="@+id/textView9"
                android:textSize="24sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout5"
            android:layout_width="100dp"
            android:layout_height="1dp"
            android:clickable="true"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal">
            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:id="@+id/rseparator"
                android:scaleType="fitXY"
                android:background="#000000"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="20dp" />
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp">

        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal" >

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="100dp"
                android:layout_height="60dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="2dp"
                android:src="@drawable/gplus_icon" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="100dp"
            android:layout_height="wrap_content"

            android:clickable="true"
            android:orientation="horizontal"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="100dp"
                android:layout_height="60dp"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="2dp"
                android:src="@drawable/facebook_icon" />

        </LinearLayout>
    </LinearLayout>

</LinearLayout>

我使用以下代码设置错误文本:

 boolean hasError = false;

            if (!Utils.isValidEmail(emailTxt.getText().toString().trim()))
            {
                emailTxt.setError("Invalid Email Address");
                hasError = true;
            }
            if (nameTxt.getText().toString().trim().length() == 0)
            {
                nameTxt.setError("Please Provide a Full Name");
                hasError = true;
            }
            if (passwordTxt.getText().length() < 4)
            {
                passwordTxt.setError("Password Must be greater than 6 character");
                hasError = true;
            }
            if (phoneNoTxt.getText().length() < 13)
            {
                phoneNoTxt.setError("Invalid Phone No");
                hasError = true;
            }

我的edittext主题,在values / style.xml中定义:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
</style>
<style name = "AppThemeNoActionBar" parent = "Theme.AppCompat.Light.NoActionBar">

</style>

<style name="CleanRideEditText" parent="Widget.AppCompat.EditText">
    <item name="colorControlNormal">#757575</item>
    <item name="colorControlActivated">#29aae1</item>
    <item name="colorControlHighlight">#757575</item>
</style>

任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:2)

我认为这与您的DATAFILETYPE = 'widenative'风格有关:EditText。尝试删除它,然后检查一切是否正常,或在此处发布您的风格。

还尝试清理项目:在Android Studio Build&gt;中清洁项目。它有时会创造奇迹。