提交 88a40ae5 编写于 作者: D dongdawei1

自定义shape,layer-list,selector

上级 8727ef21
<?xml version="1.0" encoding="utf-8"?>
<!--矩形虚线边框-内填充-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="@android:color/holo_red_light"
android:width="2dp"
android:dashGap="5dp"
android:dashWidth="10dp"/>
<solid android:color="@android:color/holo_green_light"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- 矩形内部填充-扫描渐变 -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:useLevel="true">
<!--如果布局中没有设置View的大小,会size设置的大小为默认值-->
<size
android:width="20dp"
android:height="20dp" />
<stroke
android:width="1px"
android:color="#ffff00ff" />
<!--调整angle不能实现角度变化
centerX,centerY是中心点的位置,这里用的是百分比值(0-1)
在rect中gradientRadius无效-->
<gradient
android:angle="0"
android:centerX="0.5"
android:centerY="0.5"
android:startColor="#ff00ff00"
android:gradientRadius="20dp"
android:type="sweep" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--圆角矩形-有边框有填充-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="@android:color/holo_red_light" />
<solid android:color="@color/purple_200" />
<corners android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomLeftRadius="15dp"
android:bottomRightRadius="15dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- 矩形圆角+左右两边为一个圆弧 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size android:width="20dp"
android:height="60dp" />
<solid android:color="#8000ff00" />
<!-- 圆角半径是高度的一般就是一个圆弧了 -->
<corners android:radius="20dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--矩形实线边框-内填充-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:color="@android:color/holo_red_dark"
android:width="2dp"/>
<solid android:color="@android:color/holo_blue_light" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!-- 圆环-仅有边框 -->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="ring"
android:innerRadius="20dp"
android:thickness="16dp"
android:useLevel="false">
<!--android:useLevel="false"必须是false-->
<size
android:width="80dp"
android:height="80dp" />
<stroke
android:width="3dp"
android:color="#ffff00ff" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--选择器-->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!--按下状态显示样式-->
<item android:state_pressed="true">
<!--分层-->
<layer-list>
<!--分层 第一层-->
<item android:bottom="8dp">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<!--分层 第二层-->
<item>
<shape>
<corners android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
<solid android:color="#ffaaaaaa" />
<padding android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="0dp" />
</shape>
</item>
<!--分层 第三层-->
<item>
<shape>
<corners android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
</layer-list>
</item>
<!--正常状态显示样式-->
<item>
<layer-list>
<item android:bottom="8dp">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4dp"
android:bottomRightRadius="4dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
<solid android:color="#ffaaaaaa" />
<padding android:bottom="1dp"
android:left="1dp"
android:right="1dp" android:top="0dp" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="1dp" android:topRightRadius="1dp" />
<solid android:color="@android:color/holo_blue_light" />
</shape>
</item>
</layer-list>
</item>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- android:shape="">-->
<!-- <corners />-->
<!-- <gradient />-->
<!-- <padding />-->
<!-- <size />-->
<!-- <solid />-->
<!-- <stroke />-->
</shape>
\ No newline at end of file
......@@ -27,6 +27,8 @@
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="3dp"
android:text="添加数据"
android:backgroundTint="@null"
android:background="@drawable/selector_practice"
android:id="@+id/add_btn_data"/>
<Button
android:layout_width="match_parent"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="矩形实线边框-内填充"
android:background="@drawable/rect_solid_border"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="10dp"
android:text="矩形虚线边框-内填充"
android:background="@drawable/rect_dashed_border"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:padding="10dp"
android:text="圆角矩形-有边框有填充"
android:background="@drawable/rect_rounded_border_and_fill"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/rect_rounded_top_bottom_arc" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/rect_gradient_sweep" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/ring_border" />
</LinearLayout>
\ No newline at end of file
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.FloatWindowL" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.FloatWindowL" parent="Theme.AppCompat.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册