当前位置: 移动技术网 > IT编程>移动开发>Android > Android中给按钮同时设置背景和圆角示例代码

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

2019年07月24日  | 移动技术网IT编程  | 我要评论

巅峰家教智慧,联合早报胡薄之争,老男孩之猛龙过江快播

前言

最近在做按钮的时候遇到在给按钮设置一张图片作为背景的同时还要自己定义圆角,最简单的做法就是直接切张圆角图作为按钮就可以了,但是如果不这样该怎么办呢,看代码:

下面来看效果图

一、先建一个圆角的shape文件:

<?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>

二、建立list文件:

<?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>

三、直接引用:

<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="按钮" />

总结

以上就是android中给按钮同时设置背景和圆角的方法,大家都学会了吗?希望这篇文章的内容对大家学习或者使用android能有所帮助,如果有疑问大家可以留言交流。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网