带圆角的 TextInputLayout passwordToggle
TextInputLayout passwordToggle with rounded corners
我正在使用 TextInputLayout
来自 android 设计库版本 25.1.1。使用以下代码:
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:passwordToggleEnabled="true"
local:hintEnabled="false">
<android.support.design.widget.TextInputEditText
android:id="@+id/confirmationEditText"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
但是当按下密码切换图标时,它的波纹效果绘制在TextInput的背景之上:
如何为 passwordToggle
设置圆角半径?我可以引用其现有背景并 "wrap" 它具有所需的属性(如何找到切换使用的默认可绘制对象的路径)?
为此使用自定义形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="@color/something"
android:centerColor="@color/something_else"
android:startColor="@color/something_else_still"
android:angle="270" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
我尝试在新项目上实施以了解您的情况。
请查看 solution.I 附上的屏幕截图。
您必须在 drawable 文件夹中包含 drawable 并将其设置为 TextInputEditText
的背景
round_corner_toggle.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:left="20dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#d8d8d8" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:right="60dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#ecf0f1" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
Content for TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="8"
android:background="#FFFFFF"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorPrimary">
<android.support.design.widget.TextInputEditText
android:id="@+id/tietPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:background="@drawable/round_corner_toggle"
android:inputType="textPassword"
android:padding="@dimen/activity_horizontal_margin"
android:maxLength="8" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
我知道已经有一段时间了,但是将它添加到您的 TextInputLayout 中是可行的:
app:boxCornerRadiusBottomEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusTopStart="20dp"
只需使用 Material 组件库和标准 TextInputLayout
组件。
添加app:boxCornerRadiusBottomEnd="xxdp"
,app:boxCornerRadiusTopEnd="xxdp"
,app:boxCornerRadiusBottomStart="xxdp"
, app:boxCornerRadiusTopStart="xxdp"
属性.
类似于:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:endIconMode="password_toggle"
app:boxCornerRadiusBottomEnd="8dp"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusBottomStart="8dp"
app:boxCornerRadiusTopStart="8dp"
...>
否则您可以定义自定义样式并使用 shapeAppearanceOverlay
属性:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/custom_end_icon"
android:hint="Hint text"
style="@style/OutlinedRoundedBox"
...>
与:
<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded</item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>
我正在使用 TextInputLayout
来自 android 设计库版本 25.1.1。使用以下代码:
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
local:passwordToggleEnabled="true"
local:hintEnabled="false">
<android.support.design.widget.TextInputEditText
android:id="@+id/confirmationEditText"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
但是当按下密码切换图标时,它的波纹效果绘制在TextInput的背景之上:
如何为 passwordToggle
设置圆角半径?我可以引用其现有背景并 "wrap" 它具有所需的属性(如何找到切换使用的默认可绘制对象的路径)?
为此使用自定义形状:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:endColor="@color/something"
android:centerColor="@color/something_else"
android:startColor="@color/something_else_still"
android:angle="270" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
我尝试在新项目上实施以了解您的情况。
请查看 solution.I 附上的屏幕截图。
您必须在 drawable 文件夹中包含 drawable 并将其设置为 TextInputEditText
的背景round_corner_toggle.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:left="20dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#d8d8d8" />
<corners android:radius="5dp" />
</shape>
</item>
<item android:right="60dp">
<shape android:shape="rectangle" >
<size android:height="20dp" />
<solid android:color="#ecf0f1" />
<corners android:radius="5dp" />
</shape>
</item>
</layer-list>
Content for TextInputLayout
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:counterEnabled="true"
app:counterMaxLength="8"
android:background="#FFFFFF"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/colorPrimary">
<android.support.design.widget.TextInputEditText
android:id="@+id/tietPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:background="@drawable/round_corner_toggle"
android:inputType="textPassword"
android:padding="@dimen/activity_horizontal_margin"
android:maxLength="8" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
我知道已经有一段时间了,但是将它添加到您的 TextInputLayout 中是可行的:
app:boxCornerRadiusBottomEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusTopStart="20dp"
只需使用 Material 组件库和标准 TextInputLayout
组件。
添加app:boxCornerRadiusBottomEnd="xxdp"
,app:boxCornerRadiusTopEnd="xxdp"
,app:boxCornerRadiusBottomStart="xxdp"
, app:boxCornerRadiusTopStart="xxdp"
属性.
类似于:
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:endIconMode="password_toggle"
app:boxCornerRadiusBottomEnd="8dp"
app:boxCornerRadiusTopEnd="8dp"
app:boxCornerRadiusBottomStart="8dp"
app:boxCornerRadiusTopStart="8dp"
...>
否则您可以定义自定义样式并使用 shapeAppearanceOverlay
属性:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/custom_end_icon"
android:hint="Hint text"
style="@style/OutlinedRoundedBox"
...>
与:
<style name="OutlinedRoundedBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox">
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded</item>
</style>
<style name="ShapeAppearanceOverlay.MyApp.TextInputLayout.Rounded" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">8dp</item>
</style>