Android笔记:自定义Button
2016-12-15 15:56
218 查看
在drawable下新建一个xml文件,直接把代码复制进去,完成之后直接在布局的button里设置background即可。
代码展示:
布局文件
代码展示:
布局文件
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:id="@+id/id_welcome1" android:layout_height="match_parent" android:background="@mipmap/welcome3" > <!--#F6FBFF--> <Button android:id="@+id/btn_start" android:layout_width="200dp" android:layout_height="40dp" android:background="@drawable/shape2" android:text="立即体验" android:layout_marginBottom="51dp" android:textColor="#9BE226" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> </RelativeLayout> shape2.xml文件
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape android:shape="rectangle"> <corners android:radius="4dp" /> <stroke android:width="1dp" android:color="#cccccc"></stroke> <gradient android:angle="270" android:endColor="#ffebd8" android:startColor="#f5fcff" /> </shape></item> <item><shape android:shape="rectangle"> <corners android:radius="4dp" /> <stroke android:width="1dp" android:color="#dedede"></stroke> <gradient android:angle="270" android:endColor="#ece6e1" android:startColor="#fcfcfc" /> </shape></item> </selector> <!-- Android:startcolor和android:endcolor分别为起始和结束颜色 --> <!-- android:angle是渐变角度。angle=“0”,angle=“360”时,是从左到右 ;angle=“90”是从上到下;android:angle=“180”是从右到左 --> <!-- stroke:描边 --> <!-- android:color 描边的颜色 --> <!-- corners:圆角 android:radius为角的弧度,值越大角越圆。 -->
相关文章推荐
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android笔记:通过RadioGroup/RadioButton自定义tabhost的简单方法
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- Android应用开发笔记(10):制作自定义背景Button按钮、自定义形状Button的全攻略
- android笔记 自定义textview,button等控件的外观,点击效果
- 转载 :Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- android中自定义Button,设置不同背景图片。
- 【Android笔记】(2)ButtonClickPic
- android 学习笔记:自定义通用ListView/GridView,实现ListAdapter 类
- Android 笔记 之 Button
- Android笔记之 自定义程序view写法
- 自定义Button模拟ToggleButton功能,android
- Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上2种经典解决方法。
- android 自定义View1 笔记
- Android自定义Button按钮显示样式
- android 手机开发笔记--RadioGroup RadioButton
- Android游戏开发学习笔记(一):tweened animation自定义动画的实现
- Android自定义Button组件
- Android中的Button自定义点击效果
- Android自定义button的实现,未选中,按下,选中效果