用shape仿视频中蓝色按钮
在视频中,老师的leftButton和rightButton是一个蓝色的按钮,很多同学引用之后出现错误,那是因为没有可引用的资源。现在就仿制一个蓝色的按钮。
首先在drawable资源文件夹下创建一个xml文件,名称任意。这里我起名为shape。
<?xml version="1.0" encoding="utf-8" ?> <!--shape如果不声明形状默认是正方形--> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--设置圆角--> <corners android:radius="5dp"></corners> <!--设置填充色--> <solid android:color="#0066ff"></solid> <!--设置边框的颜色和宽度--> <stroke android:color="#0066ff" android:width="1dp"></stroke> </shape>
然后在布局文件中引用即可。
<ui.app.sonny.Topbar android:id="@+id/topbar" android:layout_width="match_parent" android:layout_height="40dp" custom:leftText="Back" custom:leftTextColor="#FFFFFF" custom:leftTextBackground="@drawable/shape" custom:rightText="More" custom:rightTextColor="#ffffff" custom:rightTextBackground="@drawable/shape" custom:topbarTitle="This is title" custom:titleTextColor="#ffffff"></ui.app.sonny.Topbar>
效果如下:
更多内容,请自行搜索!