本文介绍了带有双重边框和渐变的android按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个自定义按钮.此按钮应具有渐变和两个像素的边框,但内部和外部边缘的颜色应不同(例如:内部为红色,外部为黄色).
I want to create a custom button.This button should have a gradient and a two pixel border, but the inner and outer edge should be in a different color (example: inner is red and outer is yellow).
我的问题:如何对双边框进行编程(如图所示)?!
My question: how do I program the double border (like in the image)?!
图片:
我尝试了两个笔触的XML文件,但是它不起作用.
I tried with an XML file with two strokes, but it doesn't work.
我可以使用9png文件来执行此操作,但是我想使用纯编码来执行此操作.
I could do this with a 9png file, but I want to do it with pure coding.
推荐答案
btn_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<padding android:left="3.5px"
android:top="3.5px"
android:right="3.5px"
android:bottom="3.5px"/>
<solid android:color="#d4e23a"/>
</shape>
</item>
<item >
<shape android:shape="rectangle">
<padding android:left="4.5px"
android:top="4.5px"
android:right="4.5px"
android:bottom="4.5px"/>
<solid android:color="#d4413a"/>
</shape>
</item>
<item >
<shape android:shape="rectangle">
<gradient android:startColor="#37c325"
android:endColor="#2573c3"
android:angle="-90"/>
</shape>
</item>
</layer-list>
将上述xml设置为按钮背景.
set the above xml as button background.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:background="@drawable/btn_bg"
android:gravity="center"
android:padding="10dp"
android:textStyle="bold"
>
</Button>
结果:
这篇关于带有双重边框和渐变的android按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!