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);
相关推荐
客卿1231 分钟前
用两个栈实现队列
android·java·开发语言
studyForMokey28 分钟前
【Android面试】Gradle专题
android·面试·职场和发展
向上_503582912 小时前
配置Protobuf输出Java文件或kotlin文件
android·java·开发语言·kotlin
陆业聪2 小时前
AI 时代最被低估的工程师技能:把需求写清楚
android·人工智能·aigc
夏沫琅琊2 小时前
Android 的 Activity 启动模式
android
zh_xuan3 小时前
Android compose Navigation 页面导航
android·compose
luanma1509803 小时前
PHP vs C#:30字秒懂两大语言核心差异
android·开发语言·python·php·laravel
luanma1509804 小时前
Laravel 7.X核心特性深度解析
android·开发语言·php·lua·laravel
运维老曾4 小时前
Flink 1.20 使用自带jdbc source 操作步骤
android·adb·flink
陆业聪7 小时前
2026 年还在靠「感觉」调性能?Android Profiler 这样用才对
android·人工智能·性能优化