当前位置:首页 » 安卓系统 » 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资源

热点内容
python36python27 发布:2025-05-02 18:38:05 浏览:149
血管解压术 发布:2025-05-02 18:20:15 浏览:766
服务器电脑电源改万能电源 发布:2025-05-02 18:19:15 浏览:611
邮局搭建链接服务器 发布:2025-05-02 17:43:54 浏览:948
linux默认文件夹 发布:2025-05-02 17:43:52 浏览:384
战后手机版安卓怎么登录 发布:2025-05-02 17:43:16 浏览:243
linux看文件大小 发布:2025-05-02 17:43:13 浏览:275
俄罗斯云服务器 发布:2025-05-02 17:43:01 浏览:405
蟒蛇的编程 发布:2025-05-02 17:41:09 浏览:821
我的世界神奇宝贝服务器如何接任务 发布:2025-05-02 17:37:59 浏览:740