idea怎么改Android按钮颜色,GitHub - xing609/UniversalButton: 支持自定义设置矩形、圆角,一张图片或颜色,搞定背景按下高亮效果。...

UniversalButton

68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f78696e673630392f556e6976657273616c427574746f6e2e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f78696e673630392f556e6976657273616c427574746f6e2e7376673f7374796c653d666c61742d73717561726568747470733a2f2f696d672e736869656c64732e696f2f6769746875622f77617463686572732f78696e673630392f556e6976657273616c427574746f6e2e7376673f7374796c653d666c61742d737175617265266c6162656c3d5761746368

Android 自定义多样式Button

目的:解决重复引用selector,减少图片资源占用apk瘦身

如果觉得对你有用,记得点右上给个Star或Fork

f3e243cc4ad01592b01315a7c64aace0.gif

##下面只简单介绍几个常用的属性##

gradle添加依赖

在 Project 下的 build.gradle 添加

allprojects {

repositories {

...

maven { url 'https://jitpack.io' }

}

}

在 Module 下的 build.gradle 添加

dependencies {

compile 'com.github.xing609:UniversalButton:1.0'

}

1.只设置背景

android:layout_width="70dp"

android:layout_height="70dp"

android:layout_gravity="center"

app:normalDrawable="@drawable/ic_launcher" />

2.只设置正常颜色

android:id="@+id/normalBtn"

android:layout_width="wrap_content"

android:layout_height="50dp"

android:layout_gravity="center"

android:layout_marginTop="10dp"

android:text="默认矩形一种颜色"

android:paddingLeft="15dp"

android:paddingRight="15dp"

app:normalSolid="@color/c1" />

3.正常引用selector,改变字体按下颜色

android:id="@+id/selectedBtn"

android:layout_width="60dp"

android:layout_height="60dp"

android:layout_gravity="center"

android:layout_marginTop="10dp"

android:background="@drawable/sel_btn_love"

android:text="图片"

android:textSize="12sp"

app:normalTextColor="@color/c1"

app:selectedTextColor="@color/c4" />

4.设置左边圆角,右边直角

android:id="@+id/btnLeftCircle"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:text="左边45弧度圆角"

android:textAllCaps="false"

app:normalSolid="@color/c1"

app:roundButtonLeftBottomRadius="@dimen/radius_45"

app:roundButtonLeftTopRadius="@dimen/radius_45"

app:roundButtonRightBottomRadius="@dimen/radius_10" />

5.设置圆角,背景跟颜色同时改变

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:text="45弧度圆角一种颜色带按下效果"

app:normalSolid="@color/c1"

app:normalTextColor="@color/c6"

app:selectedTextColor="@color/c4"

app:roundButtonRadius="@dimen/radius_45" />

6.设置圆角,描边变色

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="10dp"

android:text="45弧度圆角按下效果变色边框"

app:normalSolid="@color/c1"

app:normalStroke="@color/c5"

app:pressedStroke="@color/c3"

app:roundButtonRadius="@dimen/radius_45"

app:strokeWidth="1dp" />

技术交流

感觉对你有帮助,记得右上角给个Star,或打赏作者喝咖啡:

zfb_pay.jpg

欢迎加入Android 学习交流群:413893967

feb5ff6651dfb0b85ca76e2d7fe6b30d.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值