我是靠谱客的博主 陶醉大叔,这篇文章主要介绍Android笔记: 按钮设置边框实例,现在分享给大家,希望可以做个参考。

多组样式,layer-list  ,item 包裹<shape>,创建login_input.xml资源文件

复制代码
1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item > <shape> <corners android:radius="25dp"></corners> <padding android:bottom="8dp" android:top="8dp" android:left="10dp" android:right="10dp"></padding> <stroke <solid android:color="#EEEEEE" /><!--背景色 不能透明否则会显示上面的下划线颜色--> </shape> </item> </layer-list>

应用:     android:background="@drawable/login_input"  资源名自定义.

复制代码
1
2
3
4
5
6
7
8
<EditText android:id="@+id/login_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/form_Label_PwdHint" android:text="@={login.password}" android:background="@drawable/login_input" android:theme="@style/Login_Input" />

Android 按钮设置边框实例

以下一Button标签为例:

这里就联系到标签<shape>,设置背景样式、边框、渐变、圆角等,各种效果的使用方法见如下代码

drawable文件夹新建一个buttonstyle.xml,内容如下

复制代码

复制代码
1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#c0000000" android:endColor="#c0000000" android:angle="90" /><!--背景颜色渐变 angle为渐变角度--> <solid android:color="#00ffffff" /><!-- 背景填充颜色 --> <stroke android:width="3dp" android:color="#ff000000" /><!-- 描边,边框宽度、颜色 --> <corners android:radius="10dp" /><!-- 边角圆弧的半径 --> <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" /><!-- 四周留出来的空白 --> </shape>

复制代码

然后在button里面引用如下:

复制代码

复制代码
1
2
3
4
5
6
<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="按钮" android:background="@drawable/buttonstyle" />

复制代码

最后

以上就是陶醉大叔最近收集整理的关于Android笔记: 按钮设置边框实例的全部内容,更多相关Android笔记:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部