Android 正圆

复制代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="@dimen/dp_5">

    <TextView
        android:id="@+id/item_home_menu_tv"
        android:layout_width="200dp"
        android:textSize="30sp"
        android:layout_height="200dp"
        android:background="@drawable/home_menu_item_bg"
        android:gravity="center"
        android:padding="@dimen/dp_25"
        android:text="领取\n记录"
        android:textColor="@color/white" />

</RelativeLayout>


android:background="@drawable/home_menu_item_bg"



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval"
    android:useLevel="false">
    <solid android:color="#2197F0" />
    <stroke
        android:width="11dp"
        android:color="@color/white" />
    <size
        android:width="19dp"
        android:height="19dp" />
</shape>

方式2 可动态修改颜色

复制代码
tvContent.setText(getItem(position).getContent());
            GradientDrawable drawable = new GradientDrawable();
            drawable.setShape(GradientDrawable.OVAL);
            String color = "#db5860";
            if (position == 0) {
                color = "#c6f47f";
            } else if (position == 1) {
                color = "#02a4eb";
            } else if (position == 2) {
                color = "#7ecff3";
            } else if (position == 3) {
                color = "#6eb203";
            } else if (position == 4) {
                color = "#bbbb00";
            } else if (position == 5) {
                color = "#f4bc73";
            } else if (position == 6) {
                color = "#e77d8a";
            } else if (position == 7) {
                color = "#be7dfa";
            } else if (position == 8) {
                color = "#7d7dfa";
            }
            drawable.setColor(Color.parseColor(color));//背景颜色
            drawable.setStroke(dpToPx(11), ContextCompat.getColor(getContext(), R.color.white));
            drawable.setSize(dpToPx(19), dpToPx(19));
            tvContent.setBackground(drawable);
相关推荐
安卓开发者8 小时前
Android RxJava 组合操作符实战:优雅处理多数据源
android·rxjava
阿华的代码王国8 小时前
【Android】RecyclerView复用CheckBox的异常状态
android·xml·java·前端·后端
一条上岸小咸鱼8 小时前
Kotlin 基本数据类型(三):Booleans、Characters
android·前端·kotlin
Jerry说前后端9 小时前
RecyclerView 性能优化:从原理到实践的深度优化方案
android·前端·性能优化
alexhilton10 小时前
深入浅出着色器:极坐标系与炫酷环形进度条
android·kotlin·android jetpack
一条上岸小咸鱼15 小时前
Kotlin 基本数据类型(一):Numbers
android·前端·kotlin
Huntto16 小时前
最小二乘法计算触摸事件速度
android·最小二乘法·触摸事件·速度估计
一笑的小酒馆16 小时前
Android中使用Compose实现各种样式Dialog
android
红橙Darren16 小时前
手写操作系统 - 编译链接与运行
android·ios·客户端
鹏多多.20 小时前
flutter-使用device_info_plus获取手机设备信息完整指南
android·前端·flutter·ios·数据分析·前端框架