简体   繁体   English

设置材料芯片图标笔触/背景色

[英]Setting Material chip Icon stroke/background color

so I'm trying to generate a button that looks like this 所以我试图生成一个看起来像这样的按钮 在此处输入图片说明

so far what I've achieved looks like this 到目前为止,我所取得的成就看起来像这样 中号

This is the code I'm using 这是我正在使用的代码

                chip.setChipStrokeColorResource(R.color.utilitiesColor)
                chip.chipStrokeWidth = 2.0f
                chip.setChipIconTintResource(R.color.utilitiesColor)  //T
                chip.setCloseIconTintResource(R.color.utilitiesColor) //T
                chip.setTextColor(Color.parseColor("#115fff"))
                chip.setTypeface(null, Typeface.BOLD)
                chip.chipIcon = ContextCompat.getDrawable(this.context, R.drawable.ic_utilities)

The 2 lines i've commented with T are the ones I tried adding to achieve this icon background color but they don't seem to change anything, you may not see the icon in the picture but it's there its just white on white so you can't see without the stroke. 我用T注释过的2行是我尝试添加的行,以实现此图标的背景颜色,但它们似乎并没有改变任何内容,您可能看不到图片中的图标,但那里只是白色,因此您没有中风就看不到

Any help is appreciated. 任何帮助表示赞赏。

Please check this formate 请检查这个队友

<android.support.constraint.ConstraintLayout
    android:layout_width="150dp"
    android:layout_height="50dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:id="@+id/text1"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="@drawable/round_button">



    <TextView
        android:layout_width="150dp"
        android:layout_height="50dp"
        android:gravity="center"
        android:text="Utilites (200)"
        android:layout_marginEnd="10dp"
        android:paddingLeft="5dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:textAlignment="viewEnd"
         />

</android.support.constraint.ConstraintLayout>

<ImageView
    android:id="@+id/imageView"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginStart="120dp"
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toEndOf="@id/text1"
    app:srcCompat="@drawable/your_image" />

round.xml round.xml

<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />

<solid android:color="@android:color/white" />
<stroke
    android:color="@android:color/holo_blue_dark"
    android:width="2dp">

</stroke>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 以编程方式设置材料芯片的背景颜色 - Set background color of the material chip programmatically 如何在不透明的android中更改芯片背景和描边颜色 - how to change Chip Background and Stroke color in android with opacity 在过滤器样式材料组件芯片(Android)中检查图标颜色 - Checked icon color in filter style Material Components Chip (Android) 我可以在材料芯片上创建渐变背景颜色吗? - Can I create a gradient background color on a material Chip? Android - 与 BottomSheet Material 3 一起使用时芯片背景颜色发生变化 - Android - Chip background color changes when used with BottomSheet Material 3 Android材料按钮设置图标和背景颜色不起作用? - Android material button set icon and background color not working? 设置 com.google.android.material.chip.Chip 选择的颜色 - Set com.google.android.material.chip.Chip selected color 在下拉菜单中更改 Material TextInputLayout 描边颜色 state - Change Material TextInputLayout stroke color in dropdown state MaterialCardView 以编程方式更改背景颜色和描边颜色 - MaterialCardView change background color and stroke color programmatically 在应用未运行时设置小通知图标背景颜色 - Setting small notification icon background color while app is not running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM