[英]Make a shape to look like a button
I do have a group of buttons, which I am customizing using selector-shape. 我确实有一组按钮,这些按钮是使用选择器形状自定义的。 Here is the code and image of what i have so far: 这是到目前为止的代码和图像:
CODE-bgbtn.xml CODE-bgbtn.xml
<item android:state_pressed="true" >
<shape>
<solid
android:color="#004dfd" />
<stroke
android:width="1dp"
android:color="#2f3436" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="#425262"
android:endColor="#51677d"
android:angle="45" />
<stroke
android:width="1dp"
android:color="#2f3436" />
<corners
android:radius="0dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
And the results of this: 结果如下:
I have applied the style only for first button, as you can see it looks too flat. 我仅将样式应用于第一个按钮,因为您看到它看起来太平了。 How to make it look more as a button? 如何使它看起来更像一个按钮?
Try this: 尝试这个:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true"
android:state_pressed="true">
<shape android:padding="10dp" android:shape="rectangle">
<gradient android:startColor="@color/yourColor" android:endColor="@color/yourColor" android:angle="90"/>
<stroke android:width="2dp" android:color="#3E4976" />
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true" android:state_focused="true">
<shape android:padding="10dp" android:shape="rectangle">
<gradient android:startColor="@color/yourColor" android:endColor="@color/yourColor" android:angle="90"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
<item android:state_enabled="true">
<shape android:padding="10dp"
android:shape="rectangle">
<gradient android:startColor="@color/yourColor" android:endColor="@color/yourColor" android:angle="90"/>
<corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp" />
</shape>
</item>
</selector>
And then setBackground for button 然后设置按钮的背景
android:background="@drawable/custom_button"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.