Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用“显示密码”按钮设计密码文本_Android_Xml_Android Edittext_Imageview - Fatal编程技术网

Android 使用“显示密码”按钮设计密码文本

Android 使用“显示密码”按钮设计密码文本,android,xml,android-edittext,imageview,Android,Xml,Android Edittext,Imageview,我正在尝试使用show password imageView为密码设计EditText。但是,我无法正确设计它,因为我无法看到ImageView,因为EditText的布局

我正在尝试使用show password imageView为密码设计
EditText
。但是,我无法正确设计它,因为我无法看到
ImageView
,因为
EditText的布局
。当我将其更改为
wrap_content
时,我可以看到我的
ImageView
,但它在UI中看起来非常糟糕。有没有可能在不给出固定尺寸的情况下进行设计

这是我的密码

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="8dp"
            android:orientation="horizontal"
            android:layout_marginBottom="8dp">

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="horizontal">

            <EditText
                android:id="@+id/registerPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:hint="@string/register_password"
                android:inputType="textPassword" />
            <ImageView
                android:id="@+id/fragment_login_password_visibility"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:src="@android:drawable/ic_partial_secure"
                android:layout_gravity="center"
                android:clickable="true"/>

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


您是否尝试使用重量

android:layout\u weight=“1”

android:layout\u width=“0dp”
android:layout\u width=“wrap\u content”


您是否尝试使用重量

android:layout\u weight=“1”

android:layout\u width=“0dp”
android:layout\u width=“wrap\u content”



第一组
android:weightSum
LinearLayout
设置为“1”。然后,将
EditText
android:layout\u width
android:layou weight
分别设置为“0dp”和“1”。

LinearLayout
的第一组
android:weightSum
设置为“1”。然后,将
EditText
android:layout\u width
android:layout\u weight
分别设置为“0dp”和“1”。

您不需要使用ImageView

支持库增加了对中密码可见性切换的支持(版本24.2.0-2016年8月)

试试看:

setPasswordVisibilityToggleDrawable(整数剩余)

设置用于密码可见性切换按钮的图标


您不需要使用ImageView

支持库增加了对中密码可见性切换的支持(版本24.2.0-2016年8月)

试试看:

setPasswordVisibilityToggleDrawable(整数剩余)

设置用于密码可见性切换按钮的图标

试试这个:

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <EditText
                android:id="@+id/editText"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:singleLine="true"
                android:textSize="25sp"
                android:paddingRight="60dp"
                />
            <ImageButton
                android:id="@+id/showpass"
                android:layout_marginLeft="-60dp"
                style="?android:buttonBarButtonStyle"
                android:paddingBottom="5dp"
                android:src="@drawable/pass_ic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

试试这个:

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <EditText
                android:id="@+id/editText"
                android:layout_weight="1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="Password"
                android:singleLine="true"
                android:textSize="25sp"
                android:paddingRight="60dp"
                />
            <ImageButton
                android:id="@+id/showpass"
                android:layout_marginLeft="-60dp"
                style="?android:buttonBarButtonStyle"
                android:paddingBottom="5dp"
                android:src="@drawable/pass_ic"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </LinearLayout>

我建议使用带有passwordToggleDrawable的TextInputLayout

  <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputPasswordLayout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:passwordToggleContentDescription="Show" 
            app:passwordToggleDrawable="@drawable/ic_password_visibility_selector"
            app:passwordToggleEnabled="true">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/textInputEditTextPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:fontFamily="sans-serif-light"
                android:gravity="bottom"
                android:hint="@string/enter_your_password"/>


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


app:passwordToggleDrawable=“@drawable/ic\u password\u visibility\u selector”
分配您的drawable

我建议使用带有passwordToggleDrawable的TextInputLayout

  <android.support.design.widget.TextInputLayout
            android:id="@+id/textInputPasswordLayout"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:passwordToggleContentDescription="Show" 
            app:passwordToggleDrawable="@drawable/ic_password_visibility_selector"
            app:passwordToggleEnabled="true">

            <android.support.design.widget.TextInputEditText
                android:id="@+id/textInputEditTextPassword"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:fontFamily="sans-serif-light"
                android:gravity="bottom"
                android:hint="@string/enter_your_password"/>


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


app:passwordToggleDrawable=“@drawable/ic\u password\u visibility\u selector”
分配您的drawable

最新的支持库内置了对密码切换的支持。最新的支持库内置了对密码切换的支持。layout\u weight解决了问题,但是现在我丢失了TextInputLayout属性…layout\u weight解决了问题,但是现在我丢失了TextInputLayout属性…请查看我的编辑,更改后提示对密码字段无效这些更改与
EditText
提示无关。啊哈,那是因为LinearLayout。是否可以使用另一个选项而不是水平方向的线性布局?是的,您可以使用
RelativeLayout
,并将
ImageView
对齐到
EditText
的右侧。例如,用谷歌搜索它的用法。尝试使用
textinputtext
而不是
EditText
。参见此处示例用法:请参见我的编辑,在您的更改提示对密码字段无效后,这些更改与
EditText
提示无关。啊哈,那是因为LinearLayout。是否可以使用另一个选项而不是水平方向的线性布局?是的,您可以使用
RelativeLayout
,并将
ImageView
对齐到
EditText
的右侧。例如,用谷歌搜索它的用法。尝试使用
textinputtext
而不是
EditText
。请参见此处的用法示例: