Topic not selected by all activities

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 actions, adding the following to my manifest:

 ... <activity android:name=".MyActivity" android:theme="@style/AppTheme.AppText"/> ... 

The result is not what I expected. Only a few views picked up their own style. The following figure shows two views. The first FIELD ONE is fine. Field FIELD TWO does not pick up the style.

enter image description here

Here is the definition of these 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> 

Any idea please?

+5
source share
2 answers

Since only one view is affected, I did not mind its solution in Java with the following:

 TextInputLayout til_passw = findViewById(R.id.til_password); Typeface typeface = ResourcesCompat.getFont(this, R.font.book_family); til_passw.setTypeface(typeface); 
0
source

Themes do not seem to apply to password fields, possibly for security reasons. But I found a job to create a password field. You need to add 2 more attributes to your own 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 will 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 in the documentation, hintTextAppearance:

Sets the color, size, style of the tooltip text from the specified Resource TextAppearance.

Now that you use your style as is, it will only change the font family, but keep textSize to 8sp and textColor black. This is why I added these 2 attributes to your own style.

+4
source

Source: https://habr.com/ru/post/1274295/


All Articles