Here is my button appearance :
Which is actually defined by :
<Button
style="@style/Button.Pressed"
android:id="@ id/standardRestock"
android:layout_width="165dp"
android:layout_height="70dp"
android:backgroundTint="@color/button_checked_style"
android:fontFamily="@font/pragatinarrow"
android:text="@string/standard"
android:textAllCaps="true"
android:textColor="@color/black"
android:textSize="24sp" />
My style is defined by :
<style name="Button.Pressed" parent="android:Widget.Button">
<item name="android:background">@drawable/dp_button_checked</item>
<item name="android:textColor">@color/black</item>
</style>
My background is currently defined by :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/grey_button_checked" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/grey_button_checked" />
<item android:drawable="@color/grey_button">
<shape>
<stroke
android:width="5dp"
android:color="@color/redcheckborder" />
<corners
android:radius="4dp"/>
</shape>
</item>
</selector>
In short, my button should be grey and red, but AS decide to keep the default colorPrimary. Uh, and i tried to change android:background to backgroundTint, keep the same.
What did I miss ?
PS : "@color/button_checked_style" looks like that :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/grey_button" android:state_checked="false" />
<item android:color="@color/redcheckborder" android:state_checked="true" />
</selector>
CodePudding user response:
You have to change the line android:state_checked="false" from "false" to "true"
CodePudding user response:
Found...Use AppCompat Button, the current one isn't modify allowed.
<androidx.appcompat.widget.AppCompatButton
instead of
<Button
and
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true">
<shape>
<solid android:color="@color/grey_button_checked"/>
<corners
android:radius="5dp"/>
<stroke
android:color="@color/redcheckborder"
android:width="4dp">
</stroke>
</shape>
</item>
<item
android:state_pressed="false">
<shape>
<solid
android:color="@color/grey_button"/>
<corners
android:radius="5dp"/>
</shape>
</item>
</selector>
in the XML drawable file