rap*_*642 12 android android-textinputlayout android-color
正如你在图片中看到的,我有一个黑色背景和白色文本的Android应用程序.然而实际上有一个"显示文本"图标看起来像一个"眼睛",它也是黑色的:(.有没有办法改变这个颜色?
activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
android:background="@color/black">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center_horizontal" />
<!-- Email Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:textColorHint="#ffffff">
<EditText android:id="@+id/input_email"
android:theme="@style/MyEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="E-Mail Address"/>
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff">
<EditText android:id="@+id/input_password"
android:theme="@style/MyEditTextTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="Password"/>
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:layout_marginBottom="24dp"
android:padding="12dp"
android:text="Login"/>
<TextView android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:text="No account yet? Create one"
android:textColor="#ffffff"
android:gravity="center"
android:textSize="16dip"/>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
strings.xml中
<resources>
<color name="bg_color">#ffffff</color>
<color name="black">#222222</color>
<style name="MyEditTextTheme">
<item name="colorControlNormal">#ffffff</item>
<item name="colorControlActivated">#ffffff</item>
<item name="colorControlHighlight">#ffffff</item>
<item name="colorAccent">@android:color/white</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textColorHint">#ffffff</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
rap*_*642 29
好吧,我找到了正确的答案,有一种方法可以自定义它的颜色. https://developer.android.com/reference/android/support/design/widget/TextInputLayout.html#attr_android.support.design:passwordToggleTint
setPasswordVisibilityToggleTintList(ColorStateList)
Run Code Online (Sandbox Code Playgroud)
更新:您可以在TextInputLayout中直接添加以下属性:
app:passwordToggleTint="#FFF"
Run Code Online (Sandbox Code Playgroud)
rapid3642的答案指向正确的方向,但我仍然需要找出究竟会起作用的方法.
请按照以下步骤更改切换画面的颜色:
创建selector_password_visibility_toggle于~/res/color/:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When password is shown as text, the drawable will be off_white coloured -->
<item android:color="@color/off_white" android:state_checked="true"/>
<item android:color="@android:color/white"/>
</selector>
Run Code Online (Sandbox Code Playgroud)添加passwordToggleTintMode和passwordToggleTint你的TextInputLayout,如下:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleTintMode="src_atop"
app:passwordToggleTint="@color/selector_password_visibility_toggle"
app:passwordToggleEnabled="true">
Run Code Online (Sandbox Code Playgroud)现在你的TextInputLayout遗嘱颜色会改变.
在您的布局中添加以下xmlns:app。
xmlns:app="http://schemas.android.com/apk/res-auto"
现在在EditText中相应地设置passwordToggleEnabled 和 passwordToggleTint
app:passwordToggleEnabled = "true"
app:passwordToggleTint="#FFFFFF"
这是一种以编程方式执行此操作的好方法:
setPasswordVisibilityToggleTintList(AppCompatResources.getColorStateList(context, R.color.white));
Run Code Online (Sandbox Code Playgroud)
在TextInputLayout对象上调用此方法。
| 归档时间: |
|
| 查看次数: |
10752 次 |
| 最近记录: |