源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中给按钮同时设置背景和圆角示例代码

  • 时间:2022-02-28 06:16 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android中给按钮同时设置背景和圆角示例代码
[b]前言[/b] 最近在做按钮的时候遇到在给按钮设置一张图片作为背景的同时还要自己定义圆角,最简单的做法就是直接切张圆角图作为按钮就可以了,但是如果不这样该怎么办呢,看代码: [b]下面来看效果图[/b] [img]http://files.jb51.net/file_images/article/201610/20161017111532181.png?201691711160[/img] [img]http://files.jb51.net/file_images/article/201610/20161017111626504.png?2016917111634[/img] [b]一、先建一个圆角的shape文件:[/b]
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
 <corners
  android:radius="10dp"/>
 <stroke
  android:width="1dp"
  android:color="#FF6238" />
</shape>
[b]二、建立list文件:[/b]
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
 <item android:drawable="@mipmap/ic_launcher"/>
 <item android:drawable="@drawable/shape"/>
</layer-list>
[b]三、直接引用:[/b]
<TextView
 android:gravity="center"
 android:background="@drawable/list"
 android:layout_width="match_parent"
 android:layout_height="50dp"
 android:textSize="16sp"
 android:textColor="#FF0000"
 android:text="按钮" />
[b]总结[/b] 以上就是Android中给按钮同时设置背景和圆角的方法,大家都学会了吗?希望这篇文章的内容对大家学习或者使用Android能有所帮助,如果有疑问大家可以留言交流。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部