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);
相关推荐
铉铉这波能秀1 小时前
如何在Android Studio中使用Gemini进行AI Coding
android·java·人工智能·ai·kotlin·app·android studio
川石课堂软件测试2 小时前
什么是BUG,你对BUG的了解有多少?
android·linux·服务器·python·功能测试·bug·安全性测试
玩机达人885 小时前
三星S25Ultra/S24安卓16系统Oneui8成功获取完美root权限+LSP框架
android·linux·里氏替换原则
居安思危_Ho6 小时前
RK平台Uniapp自启动缓存问题解决
android·缓存·uni-app·rk平台·uniapp资源文件
molong9316 小时前
Activity/Service/Broadcast/ContentProvider 生命周期交互
android·学习·交互
molong9319 小时前
Android 权限模型(前台、后台、特殊权限)
android
怪兽20149 小时前
Looper、MessageQueue、Message及Handler的关系是什么?如何保证MessageQueue的并发访问安全?
android·面试
奥尔特星云大使9 小时前
mysql高可用架构之MHA部署(二)VIP漂移(保姆级)
android·mysql·架构·mha·ip漂移
深海呐11 小时前
Android 编译速度优化:JVM堆内存扩充
android·jvm·jvm内存扩充·android 加快编译速度