I have this custom style:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.AppText">
<item name="android:fontFamily">@font/book_family</item>
</style>
</resource>
I applied this new style as a theme to one of my activities by adding the following in my manifest:
...
<activity android:name=".MyActivity"
android:theme="@style/AppTheme.AppText"/>
...
The result is not what I expected. Only a few views picked up the custom style. The following image shows two views. The first FIELD ONE is okay. The FIELD TWO field won't pick up the style.
Here is the definition of those two fields:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<AutoCompleteTextView
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.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
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" />
</android.support.design.widget.TextInputLayout>
Please, any idea?
You can apply a theme to any activity by including android:theme inside <activity> inside manifest file.
It seems like themes don't apply to password fields, probably for security reasons. But I have found a work around to style the password field. You only need to add 2 more attributes to your custom style:
<style name="AppTheme.AppText">
<item name="android:fontFamily">@font/book_family</item>
<item name="android:textColor">@color/colorAccent</item>
<item name="android:textSize">14sp</item>
</style>
And then use app:hintTextAppearance
on your TextInputLayout
. Your password field would look like this:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/AppTheme.AppText">
<EditText
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" />
</android.support.design.widget.TextInputLayout>
Explanation: As mentioned on the documentation, hintTextAppearance:
Sets the hint text color, size, style from the specified TextAppearance resource.
Now when you use your style as it is, it will only change the font-family, but keeping the textSize
at 8sp and the textColor
black. That's why I added these 2 attributes to your custom style.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With