Setting Material chip Icon stroke/background color

核能气质少年 提交于 2019-12-24 10:57:26

问题


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.

Any help is appreciated.


回答1:


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

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



来源:https://stackoverflow.com/questions/55333780/setting-material-chip-icon-stroke-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!