zoukankan      html  css  js  c++  java
  • 2、自定义背景形状

    代码:

    <Button
    android:layout_below="@id/btn_1"因为在本次实验中,总体布局为相对布局,所以此时设置为相对btn_1向下
    android:layout_marginTop="20dp"设置与上组件外边距
    android:id="@+id/btn_2"
    android:text="按钮2"
    android:textSize="30sp"
    android:textColor="#FFFFFF"
    android:background="@drawable/bg_btn2"此时背景颜色用@导入bg_btn2(下面有介绍)
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

    第一种:圆角形式

    1、操作如下,新建drawable file

     2、弹出界面,该select为shape

     3、shape属性

    <!--*rectangle 矩形-->
    <!--*oval 椭圆-->
    <!--*line 线性-->
    <!--*ring 环形-->
    <!--基本属性:-->
    <!--* corners定义圆角-->
    <!--* solid内部填充色-->
    <!--* gradient定义渐变色-->
    <!--* angle渐变角度(仅对线性渐变有效)-->
    <!--* stroke定义描边的宽度,颜色,虚实线-->

    4、drawable file 代码

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">shape属性改为矩阵rectangle
    <stroke
    android:width="5dp"描边宽度
    android:color="#FF9900"/>描边颜色
    <solid
    android:color="#FFFFFF"/>内部填充色
    <corners
    android:radius="20dp"/>圆角弧度

    </shape>

    5、运行结果

     第二种:

     1、2、3:同上

    4、drawable file代码

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">强调为矩形
    <stroke
    android:width="5dp"描边宽度
    android:color="#FF9900"/>描边颜色
    <solid
    android:color="#FFFFFF"/>内部填充色,此时为了效果设为白色
    <corners
    android:radius="20dp"/>圆角

    </shape>

    5、运行结果

  • 相关阅读:
    162 基于UDP协议的socket套接字编程
    161 解决粘包问题
    160 粘包问题
    159 模拟ssh远程执行命令
    158 Socket抽象层
    157 基于TCP协议的socket套接字编程
    C++:查找字符串字串并替换
    C++:查找字符串字串并替换
    请问c++中的#include "stdafx.h"是什么意思?
    请问c++中的#include "stdafx.h"是什么意思?
  • 原文地址:https://www.cnblogs.com/xiaoqing-ing/p/13089824.html
Copyright © 2011-2022 走看看