i am try to use shape for background the View but my app crashed.
my code is:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="?attr/colorPrimary"
android:angle="270" />
</shape>
if replace ?attr/colorPrimary with correct color code like #9e9e9e
this code and shape word properly but when i use ?attr/ donot work and force close.how van i fix this problem?
Related
I am trying to achieve this layout. The upper part is a bit dark and it decreases as we move down making it complete transparent. I tried a couple of gradient variations but didn't get the desired results. Does anybody have idea of how to achieve this. Is it gradient or shadow ?
Create a gradient file and use this code you can increase or decrease transparency as you want
layout-->new file-->layout resource file--> give any name
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient android:startColor="#B71A1A1A"
android:angle="270"
android:centerColor="#00FFFFFF"
android:endColor="#00FFFFFF"/>
</shape>
</item>
</selector>
On Android.
I am looking for a way to create a background drawable which will give the image a transparent gradient.
Aiming to have the top of the image slightly less opaque than the original image and fade down to a completely transparent image.
Would like to do this as part of a drawable so I can apply to any of the items within a RecyclerView during run time.
Be grateful for any help if anyone has any idea.
Example - Drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/your_image"/>
<item>
<shape android:shape="rectangle">
<gradient android:startColor="#00efefef"
android:endColor="#ffefefef"
android:angle="270"
android:type="linear"/>
</shape>
</item>
</layer-list>
Since i updated my device to android 10 im facing a weird problem with one of my background gradients.
I have a RelativeLayout with a gradient background drawable looking like this.
<RelativeLayout
android:id="#+id/layoutSpeedLegend"
android:layout_width="match_parent"
android:layout_height="18dp"
android:background="#drawable/background"/>
My background.xml is looking like this.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:centerColor="#color/yellow"
android:endColor="#color/red"
android:startColor="#color/darkgreen"
android:centerX="50%"/>
<corners android:radius="15dp" />
</shape>
</item>
In the editors preview, everything looks fine
But on my real test device is looks like this.
Also adding android:angle="90" to my background.xml doesn't work.
Does anybody have an idea why this happens?
It's a bug reported here. And may not be resolved yet.
The workaround is set angle="0" as you mentioned in question's comment.
Hi i'm now developing application that contain a profile like twitter profile
I got a small problem .
the problem is how to make a gradient black trasparent mask effect like this
can anyone help me or provide me a code how to make this effect with xml please
thank's :)
If I good understood you you should create new drawable xml as below:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:startColor="#000000"
android:centerColor="#C0C0C0"
android:endColor="#FFFFFF"
android:angle="90"/>
</shape>
And set it as background on your view.
I changed in ScrollView
android:fadeScrollbars="false"
to ScrollBar be visible and it works fine. My question is possible to change color of ScrollBar ? ( Default is gray and my background is gray so there is small contrast between ).
You can with android:scrollbarThumbVertical="#drawable/youdrawable
In my case, for instance yourdrawable is:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#66C0C0C0" android:endColor="#66C0C0C0"
android:angle="45"/>
<corners android:radius="6dp" />
</shape>
You can use:android:scrollbarThumbVertical="#drawable/yourImage"
, where 'yourImage' can be a small 2 pixel image of ur desired color