Question

gradient for view pager indicator

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#000"
        android:centerColor="#00000000"
        android:endColor="#000"
        android:angle="270"
        android:dither="true"
     />
</shape>

This is the code I tried but it ends up as pure black.

Was it helpful?

Solution

What about this gradient? Full transparency at top to 50% transparent black at bottom

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#00000000"
        android:endColor="#80000000"
        android:angle="270"
        android:dither="true"
     />
</shape>

OTHER TIPS

Try this instead:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#00000000"
        android:endColor="#FF000000"
        android:angle="270"
        android:dither="true"
     />
</shape>

Add your class this code

GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {endColor,startColor}); gd.setCornerRadius(0f); layout.setBackgroundDrawable(gd); Hope this will help!

In my case it works great:


   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:angle="270"
            android:endColor="@android:color/transparent"
            android:startColor="#000000" />
    </shape>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top