android上按钮框在哪里,Android-按钮边框

博客介绍了在Android上创建带边框按钮的官方解决方案。自引入Android Design支持v28后,可使用MaterialButton创建。分别阐述了使用androidx和appcompat时的实现方式,包括在build.gradle添加依赖,以及给出带边框和未填充边框按钮的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android Official Solution

自从引入Android Design支持v28以来,使用即可轻松创建带边框的按钮MaterialButton。此类为构造函数中的按钮提供更新的Material样式。使用app:strokeColor和app:strokeWidth您可以创建自定义边框,如下所示:

1.使用时androidx:

build.gradle

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'

implementation 'com.google.android.material:material:1.0.0'

}

•带边框的按钮:

style="@style/Widget.AppCompat.Button.Colored"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="MATERIAL BUTTON"

android:textSize="15sp"

app:strokeColor="@color/green"

app:strokeWidth="2dp" />

•未填充边框按钮:

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="UNFILLED MATERIAL BUTTON"

android:textColor="@color/green"

android:textSize="15sp"

app:backgroundTint="@color/transparent"

app:cornerRadius="8dp"

app:rippleColor="#33AAAAAA"

app:strokeColor="@color/green"

app:strokeWidth="2dp" />

2.使用时appcompat:

build.gradle

dependencies {

implementation 'com.android.support:design:28.0.0'

}

style.xml

确保您的应用程序主题继承自Theme.MaterialComponents而不是Theme.AppCompat。

•带边框的按钮:

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="MATERIAL BUTTON"

android:textSize="15sp"

app:strokeColor="@color/green"

app:strokeWidth="2dp" />

•未填充边框按钮:

style="@style/Widget.AppCompat.Button.Borderless"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="UNFILLED MATERIAL BUTTON"

android:textColor="@color/green"

android:textSize="15sp"

app:backgroundTint="@color/transparent"

app:cornerRadius="8dp"

app:rippleColor="#33AAAAAA"

app:strokeColor="@color/green"

app:strokeWidth="2dp" />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值