There is a png picture and the goal is to add it to the button . The problem is that if I add via @android:background buttons, then the picture becomes with the ladders (as if anti-aliasing is turned off), or becomes muddy. If I use the markup below, then in general the picture is not shown, only the borders on the button remain.
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:bottom="2dp" android:drawable="@drawable/lmb_leaved" android:left="2dp" android:right="2dp" android:top="2dp" /> <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="30dp" /> <gradient android:angle="270" android:endColor="#000000" android:startColor="#000000" /> <stroke android:width="4px" android:color="#FF00BB2B" /> </shape> </item> </layer-list> </item> <item android:state_pressed="true"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:bottom="2dp" android:drawable="@drawable/lmb_pressed" android:left="2dp" android:right="2dp" android:top="2dp" /> <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="30dp" /> <gradient android:endColor="#000000" android:startColor="#000000" /> <stroke android:width="20px" android:color="#FF00BB2B" /> </shape> </item> </layer-list> </item> There are assumptions that incorrectly add png to the project. I add through res-> new-> image asset
Corrected, now everything works
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:src="@drawable/lkmveryhigh" /> </item> <item> <shape android:shape="rectangle"> <corners android:radius="30dp" /> <solid android:color="#0000"/> <stroke android:width="5dip" android:color="#FF00BB2B" /> </shape> </item> </layer-list> </item> <item android:state_pressed="true"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <bitmap android:src="@drawable/lkmveryhigh" /> </item> <item> <shape android:shape="rectangle"> <corners android:radius="30dp" /> <solid android:color="#0000"/> <stroke android:width="10dip" android:color="#FF00BB2B" /> </shape> </item> </layer-list> </item> </selector> I move the picture manually to the res / drawable-hdpi folder. Only there is a small problem that the android:state_pressed="true" selector android:state_pressed="true" still refuses to work.
ImageButton? - Vladyslav Matviienko 6:08 pmandroid:backgroundorandroid:src? - Vladyslav Matviienkodrawable-xhdpi- Vladyslav Matviienko 6:51 pm