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);
相关推荐
m0_748246875 小时前
MySQL8.0 innodb Cluster 高可用集群部署(MySQL、MySQL Shell、MySQL Router安装)
android·mysql·adb
crazymaple2138 小时前
Flutter编译运行android问题之JVM版本问题
android·jvm·flutter
新知图书9 小时前
ThinkPHP8视图赋值与渲染
android·ide·android studio
众智创新团队9 小时前
Android的Activity生命周期知识点总结,详情
android·java·开发语言
etcix9 小时前
安卓谷歌地图api一个文件例子(备忘)
android
xvch9 小时前
Kotlin 2.1.0 入门教程(十四)类、构造函数、对象、抽象类
android·kotlin
yzpyzp9 小时前
kotlin-kapt
android·kotlin
B.-10 小时前
Flutter 中的生命周期
android·前端·flutter·ios
xvch11 小时前
Kotlin 2.1.0 入门教程(十六)属性、getter、setter、幕后字段、后备属性、编译时常量、延迟初始化
android·kotlin
闲暇部落11 小时前
kotlin中expect和actual关键字修饰的函数作用
android·开发语言·kotlin