设置材料芯片图标笔触/背景色 [英] Setting Material chip Icon stroke/background color

查看:116
本文介绍了设置材料芯片图标笔触/背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试生成一个看起来像这样的按钮

so I'm trying to generate a button that looks like this

到目前为止,我所取得的成就看起来像这样

so far what I've achieved looks like this

这是我正在使用的代码

                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)

我用T注释过的2行是我尝试添加的行,以实现此图标的背景颜色,但它们似乎并没有改变任何内容,您可能看不到图片中的图标,但那里只是白色白色,所以没有中风就看不到.

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.

感谢您的帮助.

推荐答案

请检查该伙伴

<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

<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>

这篇关于设置材料芯片图标笔触/背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆