当前位置:首页 » 安卓系统 » androidbutton设置圆角

androidbutton设置圆角

发布时间: 2025-02-18 12:55:35

1. 安卓按钮按下效果怎么设置呢怎么设置按钮圆角和按下效果

可以通过shape设置圆角

<?xml version="1.0" encoding="utf-8"?>
<!-- shape如果不声明形状默认是正方形 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置圆角 -->
<corners android:radius="2dp" >
</corners>
<!-- 设置填充色 -->
<solid android:color="#4285f4" >
</solid>
<!-- 设置边框的颜色和宽度 -->
<stroke
android:width="1dp"
android:color="#4285f4" >
</stroke>
</shape>
通过selector设置点击效果

button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 这个是用于控制按钮组背景的文件 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- **点击时效果**********背景引用的资源*************************是否获得焦点*********************是否按下******* -->
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/button_p" android:state_focused="false" android:state_pressed="true"/>

<!-- **************没有任何操作时显示的背景************** -->
<item android:drawable="@drawable/button_n"></item>
</selector>
在xml文件中设置button的background属性。
android:background="@drawable/button_bg"

2. android如何设置Button为圆角

这里为大家介绍如果通过简单的设置,使界面上的Button圆角

在您的android工程的res目录下的drawable建立xml配置文件button_shape.xml

在button_shape.xml按照您自己的需求写入如图所示的属性

在button按钮的属性中,设置android:background="@drawable/button_shape",这样就使用了刚刚我们自定义的button_shape.xml资源

热点内容
路由器密码是什么啊 发布:2025-09-19 09:23:25 浏览:701
天蝎脚本辅助 发布:2025-09-19 09:22:31 浏览:256
官服光遇账号和密码在哪里看 发布:2025-09-19 08:57:15 浏览:649
传奇切割机脚本 发布:2025-09-19 08:35:46 浏览:74
博科存储交换机配置 发布:2025-09-19 08:34:31 浏览:138
xp共享win7没有访问权限 发布:2025-09-19 08:29:15 浏览:288
cmd运行python程序 发布:2025-09-19 08:16:07 浏览:298
如何给你的安卓手机正确充电 发布:2025-09-19 08:15:18 浏览:850
vs2010怎么写c语言 发布:2025-09-19 07:31:05 浏览:882
除了证券外还有哪些投资配置 发布:2025-09-19 07:01:48 浏览:89