material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.37k stars 3.07k forks source link

[MaterialShapeDrawable] Unable to add gradient to MaterialShapeDrawable #1167

Open railianmaksym opened 4 years ago

railianmaksym commented 4 years ago

Is your feature request related to a problem? Please describe. A have a lot of cases when I need to use a gradient with material shapes, but I can't do it because MaterialShapeDrawable used the only fillColor. If I want to use gradient or another drawable view with MaterialShapeDrawable becomes black.

Describe the solution you'd like Add the possibility to use drawables with MaterialShapeDrawable.

wcshi commented 4 years ago

"A have a lot of cases when I need to use a gradient with material shapes", could you please explain what they are?

vitorhugods commented 4 years ago

Simple widgets with gradient background, like this:

Floating Action Button: grafik

Chip: grafik

Button: grafik

Shusshu commented 4 years ago

Would be great if FloatingActionButton supported custom backgrounds like MaterialButton and ExtendedFloatingButton (which extends MaterialButton)

TurKurT656 commented 3 years ago

FloatingActionButton does not supports custom backgrounds. (for example gradient background) It would be great if we have this functionality

Shusshu commented 3 years ago

I found a workaround to get it with not too much work Use ExtendedFloatingActionButton without label (shrinked) and override the background (as it's a MaterialButton you can just do it)

TurKurT656 commented 3 years ago

I found a workaround to get it with not too much work Use ExtendedFloatingActionButton without label (shrinked) and override the background (as it's a MaterialButton you can just do it)

can you add a link or sample code?

Shusshu commented 3 years ago
    extendedFab.backgroundTintList = null
    extendedFab.setBackgroundResource(R.drawable.btn_extendedfab_shrinked_gradient)

R.drawable.btn_extendedfab_shrinked_gradient

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/btn_shape_extendedfab_shrinked_disabled" android:state_enabled="false" />

    <item android:state_enabled="true">
        <ripple android:color="?attr/colorControlHighlight">
            <item android:drawable="@drawable/btn_shape_extendedfab_shrinked_gradient" />
        </ripple>
    </item>
</selector>

btn_shape_extendedfab_shrinked_gradient

    <?xml version="1.0" encoding="utf-8"?>
    <inset xmlns:android="http://schemas.android.com/apk/res/android">
      <shape android:shape="rectangle">
        <corners android:radius="56dp" />
        <gradient
                android:angle="90"
                android:endColor="#000000"
                android:startColor="#ffffff"
                android:type="linear" />
        <padding android:left="0dp"
                android:top="0dp"
                android:right="0dp"
                android:bottom="0dp" />
      </shape>
    </inset>
sanisloandras commented 2 years ago

Still waiting for this... Have to use AppCompatButton to implement simple button with gradient background...

wiryadev commented 1 year ago

still waiting