【问题标题】:Creating a custom button with circled text inside创建一个带有圆圈文本的自定义按钮
【发布时间】:2019-07-08 14:32:44
【问题描述】:
I'm trying to make a button like so.
属性:
- 圆形
- 字母:如 A、B、C、D 等。
- 文本:任何字符串,在示例中字符串是数字。
我不知道从哪里开始。目前这是我的按钮:
文件:button.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="100dp" />
<solid android:color="@color/colorPrimary" />
<padding
android:left="16dp"
android:top="16dp"
android:right="16dp"
android:bottom="16dp"
/>
</shape>
【问题讨论】:
标签:
android
xml
user-interface
view
drawable
【解决方案1】:
基本上是这样
对于ROUNDED选项
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="#000" />
<size
android:width="40dp"
android:height="40dp" />
</shape>
并在您的活动中使用它,如下所示
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:background="@drawable/button_background_test"
android:text="A"
android:textSize="16dp"
android:gravity="center"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
您也可以用同样的方式设计外部按钮。
编码愉快!