TextView state_pressed / state_focused / state_selected style change

I am trying to change the style of a TextView based on its state. My .xml styles contain:

<style name="text_normal_ops"> <item name="android:gravity">left</item> <item name="android:textColor">@color/text_usual_color</item> <item name="android:textStyle">bold</item> </style> <style name="text_normal_ops_pressed"> <item name="android:gravity">left</item> <item name="android:textColor">@color/text_pressed</item> <item name="android:textStyle">bold</item> </style> 

My selector ( text_ops.xml ) is defined as:

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" style="@style/text_normal_ops_pressed" /> <item android:state_focused="true" style="@style/text_normal_ops_pressed" /> <item android:state_selected="true" style="@style/text_normal_ops_pressed" /> <item style="@style/text_normal_ops"/> </selector> 

But when I apply this to my texture ( style="@drawable/text_ops" ), it will not work. Any tips?
Thanks

+6
source share
2 answers

According to my knowledge, there are only two state lists in android 1. The resource of the state list is color 2. StateListDrawable. If you use a style in it, re-check the document

See the link below for more information.

+9
source

The problem is the line style="@drawable/text_ops" , which should be style = "@ style / text_ops".

I have not tried using a style selector, but it would be great if that worked.

+1
source

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


All Articles