我有这个自定义样式:
@color/colorPrimary
@color/colorPrimaryDark
@color/colorAccent
@font/book_family
我通过在清单中添加以下内容,将此新样式作为主题应用于我的一个活动:
...
android:theme="@style/AppTheme.AppText"/>
...
结果不是我的预期.只有少数几个视图选择了自定义样式.下图显示了两个视图.第一个FIELD ONE没关系. FIELD TWO字段不会提取样式.
以下是这两个字段的定义:
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="number"
android:imeOptions="actionNext"
android:maxLines="1"
android:singleLine="true" />
android:id="@+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="numberPassword"
android:maxLines="1"
android:singleLine="true" />
请问,任何想法?
解决方法:
似乎主题不适用于密码字段,可能出于安全原因.但我找到了解决密码字段样式的工作.您只需要为自定义样式添加另外两个属性:
@font/book_family
@color/colorAccent
14sp
然后在TextInputLayout上使用app:hintTextAppearance.您的密码字段如下所示:
android:id="@+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/AppTheme.AppText">
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="6"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="numberPassword"
android:maxLines="1"
android:singleLine="true" />
说明:如文档中所述,hintTextAppearance:
Sets the hint text color, size, style from the specified
TextAppearance resource.
现在,当您按原样使用样式时,它只会更改font-family,但将textSize保持在8sp,将textColor保持为黑色.这就是我将这两个属性添加到您的自定义样式的原因.
标签:android,view,themes
来源: https://codeday.me/bug/20190522/1153375.html