Android渐变色圆角按钮的实现
2014-10-12 13:09
393 查看
最终效果如:
没有使用背景图片,因为Android手机屏幕分辨率碎片化太严重,如果用图片的话需要ps n张图片。所以,使用shape实现的渐变圆角按钮。
1.在drawable文件夹下新建round.xml,内容为:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色,渐变色 -->
<gradient
android:startColor="#717a97"
android:endColor="#223158"
android:angle="90" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="5dip" />
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
2.在按钮中使用round.xml:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round"
android:text="@string/btnLogin"
android:layout_gravity="center"
android:layout_marginRight="5dip"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:textColor="#ffffff"
android:textSize="12sp"
></Button>
没有使用背景图片,因为Android手机屏幕分辨率碎片化太严重,如果用图片的话需要ps n张图片。所以,使用shape实现的渐变圆角按钮。
1.在drawable文件夹下新建round.xml,内容为:
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色,渐变色 -->
<gradient
android:startColor="#717a97"
android:endColor="#223158"
android:angle="90" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="5dip" />
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
2.在按钮中使用round.xml:
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/round"
android:text="@string/btnLogin"
android:layout_gravity="center"
android:layout_marginRight="5dip"
android:layout_centerInParent="true"
android:layout_alignParentRight="true"
android:textColor="#ffffff"
android:textSize="12sp"
></Button>
相关文章推荐
- Android 开发 圆角 Button 按钮 xml 实现
- Android实现圆角Button按钮
- Android中xml实现效果三:圆角按钮
- Android开发--圆角 Button 按钮 xml 实现
- Android按钮的渐变色的简单实现
- Android添加圆角渐变色按钮
- Android开发--圆角按钮和绘制直线的实现
- Android实现空心圆角矩形按钮的实例代码
- Android 实现圆角按钮(selector和shape的简单用法)
- Android 实现圆角按钮(selector和shape的简单用法)
- Android中快速便捷的实现圆角按钮方法详解
- android圆角按钮的实现【新浪云搬运】
- android实现的圆角按钮Button
- 【Android开发】利用XML实现扁平化按钮和圆角矩形
- Android开发--圆角按钮和绘制直线的实现
- Android 实现圆角按钮
- 转载 :Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- [Cocoa]自定义TableViewCell实现圆角/渐变色TableView
- Android中包含多个Activity的应用退出按钮实现
- Android:实现TabWidget选项卡按钮在屏幕下方