Android TextInputEditText,inputType = textPassword,我看不到点

时间:2018-05-03 05:05:02

标签: android view android-edittext

我在我的活动中使用TextInputEditText。我设置了inputType' textPassword'。 但我看不到点来保护我输入的密码。

这是我查看的源代码。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent">

    <ImageView
        android:id="@+id/email_login_background_img"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/intro_background" />

    <ImageView
        android:id="@+id/email_login_logo_img"
        android:layout_width="240dp"
        android:layout_height="32dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="24dp"
        android:scaleType="centerCrop"
        android:src="@drawable/rock_bottom_logo" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_email_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_logo_img"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_email_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_login_email_txt"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_password_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_email_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="@color/colorAccent">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_password_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/email_login_password_txt"
            android:inputType="textPassword" />
    </android.support.design.widget.TextInputLayout>


    <Button
        android:id="@+id/email_login_sign_in_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_password_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/button_custom_login"
        android:text="@string/email_login_sign_in_txt"
        android:textColor="@color/white" />

    <TextView
        android:id="@+id/email_login_sign_up_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_in_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="@string/email_login_sign_up_txt"
        android:textColor="@color/white"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/email_login_password_find_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_up_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="@string/email_login_sign_up_txt"
        android:textColor="@color/white"
        android:textSize="16sp" />

</RelativeLayout>

这是显示我问题的屏幕截图。

enter image description here

它可能看起来不太好,但点肯定根本看不到。

这是应用于我的活动的风格。

<style name="AppTheme2" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorControlActivated">@color/colorPrimary</item>
        <item name="colorControlNormal">@color/colorDarkerGray</item>
    </style>

我该如何解决这个问题。我需要你的帮助。谢谢。

此外,这是我的EmailTextInputEditText样式。

<style name="EmailTextInputEditText" parent="TextAppearance.AppCompat">
    <item name="android:textColor">@color/white</item>
    <item name="android:textColorHint">@color/white</item>
    <item name="colorControlNormal">#a90000</item>
    <item name="android:textCheckMark">@color/white</item>
</style>

此外,这是我的color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">@android:color/holo_red_dark</color>
    <color name="colorPrimaryDark">#c20000</color>
    <color name="colorPrimaryLight">#ea0000</color>
    <color name="colorAccent">@android:color/white</color>
    <color name="colorBlack">@android:color/black</color>
    <color name="colorVideoTxt">#001020</color>
    <color name="colorVideoTransparent">#92dadada</color>
    <color name="colorDarkerGray">@android:color/darker_gray</color>
    <color name="white">@android:color/white</color>
    <color name="cardBackground">#73e2e2e2</color>
    <color name="transparent">#00ffffff</color>

</resources>

2 个答案:

答案 0 :(得分:2)

试试这个 -

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:gravity="center"
    android:backgroundTint="@color/background"
    android:textColorHint="@color/background">

    <EditText
        android:id="@+id/edtxtUsrID"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Email ID"
        android:inputType="text"
        android:maxLength="30"
        android:backgroundTint="@color/view_grey"
        android:maxLines="1"/>

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

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="5dp"
    android:backgroundTint="@color/view_grey"
    android:textColorHint="@color/view_grey">

    <EditText
        android:id="@+id/edtxtUsrPswrd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:inputType="textPassword"
        android:maxLength="30"
        android:maxLines="1"
        android:backgroundTint="@color/view_grey"
        android:textColorHint="@color/view_grey" />

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

@Junburg您在TextInputEditText中添加了 - style =“@ style / EmailTextInputEditText”,从TextInputEditText删除该行,请参见下面的屏幕截图enter image description here

答案 1 :(得分:1)

主题问题请尝试以下代码

试试这个

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/goku" />


    <ImageView
        android:id="@+id/email_login_logo_img"
        android:layout_width="240dp"
        android:layout_height="32dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="24dp"
        android:scaleType="centerCrop"
        android:src="@color/colorPrimary" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_email_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_logo_img"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_email_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email_login_email_txt"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_password_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_email_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="@color/colorAccent">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_password_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email_login_password_txt"
            android:text="123456"
            android:inputType="textPassword" />
    </android.support.design.widget.TextInputLayout>


    <Button
        android:id="@+id/email_login_sign_in_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_password_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@color/colorPrimary"
        android:text="email_login_sign_in_txt"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/email_login_sign_up_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_in_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="email_login_sign_up_txt"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/email_login_password_find_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_up_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="email_login_sign_up_txt"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />

</RelativeLayout>
  

主题

 <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
        <item name="colorControlActivated">@color/colorPrimary</item>
        <item name="colorControlNormal">#787777</item>
    </style>

    <style name="EmailTextInputEditText" parent="TextAppearance.AppCompat">
        <item name="android:textColor">@color/white</item>
        <item name="android:textColorHint">@color/white</item>
        <item name="colorControlNormal">#a90000</item>
        <item name="android:textCheckMark">@color/white</item>
    </style>

结果使用IMAGEVIEW

enter image description here

注意:也无需额外imageView删除它,只需将背景设置为RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
    android:background="@drawable/goku">


    <ImageView
        android:id="@+id/email_login_logo_img"
        android:layout_width="240dp"
        android:layout_height="32dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="24dp"
        android:scaleType="centerCrop"
        android:src="@color/colorPrimary" />

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_email_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_logo_img"
        android:layout_marginBottom="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_email_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email_login_email_txt"
            android:inputType="textEmailAddress" />
    </android.support.design.widget.TextInputLayout>

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_login_password_layout"
        style="@style/EmailTextInputEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_email_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        app:passwordToggleEnabled="true"
        app:passwordToggleTint="@color/colorAccent">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email_login_password_txt"
            style="@style/EmailTextInputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email_login_password_txt"
            android:text="123456"
            android:inputType="textPassword" />
    </android.support.design.widget.TextInputLayout>


    <Button
        android:id="@+id/email_login_sign_in_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/email_login_password_layout"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="8dp"
        android:background="@color/colorPrimary"
        android:text="email_login_sign_in_txt"
        android:textColor="#FFFFFF" />

    <TextView
        android:id="@+id/email_login_sign_up_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_in_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="email_login_sign_up_txt"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/email_login_password_find_btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/email_login_sign_up_btn"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="48dp"
        android:gravity="center"
        android:text="email_login_sign_up_txt"
        android:textColor="#FFFFFF"
        android:textSize="16sp" />

</RelativeLayout>

结果使用不使用IMAGEVIEW

enter image description here