当前位置:首页 » 安卓系统 » android按钮边框

android按钮边框

发布时间: 2025-05-22 02:29:55

1. 怎么给android 设置边框

1.首先在res目录下新建一个xml文件,类型选择drawable,将自动生一个一个drawable文件(我用的sdk是android 4.1),并生成一个xml文件,在其中写入以下代码:

[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#FFFFFF" />

<stroke
android:width="0.01dp"
android:color="#FFFFFF" />

<padding
android:bottom="1dp"
android:left="0.5dp"
android:right="0.5dp"
android:top="0dp" />
</shape>

2.在要设置边框的控件xml命令里加入:android:background=“@drawable/boder”

2. android怎么给tablerow添加边框

总结一下android ui界面里面如何设置边框,以及如何把边框设置成弧形的即圆角。
其实,android的ui里,界面一般都是比较简单的,不会像web页面那样,数据量比较大,关于给android界面(表格)设置边框,其思想很想我们用HTML设计表格然后给它设置边框,如果你懂html的话。即通过给不同的控件设置背景颜色来反衬出边框线
以一个登录界面为例,设置一个有边框线的android 登录界面:
注:本例要求的只是将该TableLayout中的行与行之间用边框线隔开
此例中,采用TableLayout布局,非常简单,里面有3个TableRow,分别放置 用户名、密码、登录按钮,根据上面说的设置边框线只需要设置控件的背景颜色即可。这个例子中要求行与行之间有边框线,那么,就这么想,
TableLayout:是该界面的布局管理器(当然也是一个控件),放在最外层,那么这时你可以给它选一个背景颜色参考注释 a)
TableRow:是表格中的一行,设置边框线重点就在此,它是紧跟着TableLayout的,可以给TableRow(行)设置背景色,参考b)
TableLayout与TableRow关系:可以看成父与子的关系,那么不管怎么样,TableLayout总是大于TableRow,那么通过给二者设置不同的颜色,设置颜色的时候可以让子组件(TableRow)周围稍微留出一点边界(就是它的背景色不会覆盖完整个行,如何让它显示成这样呢=====>android:layout_margin="0.5dip"[此属性即是设置该组件周围留出一点边界])
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#ffcccccc" //a)给tablelayout设置背景色,改背景颜色将会是你要设置的边框线的背景色
android:layout_margin="1dip"
>
<!--android:background="@drawable/view_shape" -->
<TableRow
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)给tablerow设置背景色
android:layout_margin="0.5dip" //c)非常重要的一点
>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Name"
android:textStyle="bold"
android:layout_gravity="center_vertical" //如果想让表格里的列与列(column之间)也有边框线隔开,则同上面一样也要设置android:background="#ffffcc99"与android:layout_margin="0.5dip"
>
</TextView>
<EditText
android:id="@+id/widget42"
android:layout_width="141px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
<TextView
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
>
</TextView>
<EditText
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<Button
android:id="@+id/widget46"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textColor="#ff000000"
android:layout_margin="2dip"
android:background="#ffffcc33"
>
<!--android:background="@drawable/view_shape" -->
</Button>
</TableLayout>

3. android button 怎么消除边框

使用资源文件shape定义背景(background)

下图是安卓无忧中的例子,可以看里面的源码还有文档,大部分形状都可以定义,请看截图:

在Android程序开发中,我们经常会去用到Shape这个东西去定义各种各样的形状,首先我们了解一下

Shape下面有哪些标签,都代表什么意思:

1.1 solid:填充

android:color指定填充的颜色

1.2 gradient:渐变

android:startColor和android:endColor分别为起始和结束颜色,

android:angle是渐变角度,必须为45的整数倍。

另外渐变默认的模式为android:type="linear",即线性渐变,

可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

angle值对应的位置如图:

1.3 stroke:描边

android:width="2dp" 描边的宽度,android:color 描边的颜色。

我们还可以把描边弄成虚线的形式,设置方式为:

android:dashWidth="5dp"

android:dashGap="3dp"

其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离

1.4 corners:圆角

android:radius为角的弧度,值越大角越圆。

我们还可以把四个角设定成不同的角度,

同时设置五个属性,则Radius属性无效

android:Radius="20dp" 设置四个角的半径

android:topLeftRadius="20dp" 设置左上角的半径

android:topRightRadius="20dp" 设置右上角的半径

android:bottomLeftRadius="20dp" 设置右下角的半径

android:bottomRightRadius="20dp" 设置左下角的半径

padding:间隔

可以设置上下左右四个方向的间隔

ps:为了方便交流看一下我名字中文和除了中文以外的。

热点内容
哔咔漫画缓存路径 发布:2025-05-22 12:20:51 浏览:591
有的服务器为什么放水里 发布:2025-05-22 12:04:40 浏览:994
解压球成分排名 发布:2025-05-22 11:51:03 浏览:82
网站打赏源码 发布:2025-05-22 11:43:59 浏览:254
c语言与visualstudio 发布:2025-05-22 11:43:15 浏览:713
android应用隐藏 发布:2025-05-22 11:31:02 浏览:249
外边学编程 发布:2025-05-22 11:17:46 浏览:266
python爬虫模拟点击 发布:2025-05-22 11:13:59 浏览:865
kkm汉化组解压密码是什么 发布:2025-05-22 11:08:45 浏览:56
保存的游戏账号和密码在哪里 发布:2025-05-22 11:07:29 浏览:362