问题
I'm trying to draw highlight "3D" lines on a button using a stroke. How do I do this? The below chunk from my custom_button.xml selector is for the default button state. I'm expecting the background of the button to be filled with a blue gradient but a pink (just for testing!) line to appear on the left side of the button.
Should I be using a layer-list as shown below? How do I get the line to appear on just the left of the button? At present the pink line appears around the entire button and it fills the button with black instead of the gradient blue. Is this because the second item's default color is black.. even though I am trying to set it to transparent?
<shape>
<gradient
android:endColor="@color/blue2"
android:startColor="@color/blue25"
android:angle="270" />
<stroke
android:width="3dp"
android:color="#00FFFF" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
<item android:left="1dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="#FF8888" />
</shape>
</item>
</layer-list>
Below is an image of what I get (on top) and what I expect to get (on the bottom). I'm only using these colours for test purposes! :-)
回答1:
You can try this
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="-2dp"
android:right="-2dp"
android:top="-2dp">
<shape>
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#FF8888" />
</shape>
</item>
<item
android:drawable="@drawable/shape2"
android:left="1dp">
</item>
</layer-list>
Where @drawable/shape2
is the shape you specified above
result:
来源:https://stackoverflow.com/questions/24153167/android-stroke-left-side-of-button-only