I was wondering, what would be the best way to make a gradient background for a LinearLayout in java ( not xml ) ?
Any ideas?
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#006499"
android:endColor="#0093d7"
android:angle="90" />
</shape>
Set here startColor and endColor as your requirement and save this file in drawable folder
and in LinearLayout you can set this as setBackground="#drawable/your gradient filename"
Using java code you can do same thing using GradientDrawable
Besides xml you can also use GradientDrawable it has corresponding methods for all xml attributes
Related
how to make a gradient color background like this in xml android?
Can we make like this background in android?
The image you provide is not a gradient it's normal image but to make gradient in android you can do this:
1- create new drawable resource file
2-change selector to shape
3- inside shape u can start creating your gradient like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:type="linear"
android:angle="90"
android:startColor="#f6ee19"
android:endColor="#115ede" />
</shape>
I am using MPAndroid Chart for my project.
I want to make the styling of LineChart as follows. Basically I want all 4 Quadrants and other styling like gradient colors etc.
First make it to fill color behind line by doing this:
dataset.setDrawFilled(true);
After that you have to give gradient for that you have make an xml file like that in drawables as gradient_chart_color:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:angle="90"
android:startColor="#FFF300"
android:endColor="#F5F094" />
</shape>
After that you have to do this :
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
dataset.setFillDrawable(drawable);
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?
I want to show edit text box with two sides. so, for that i need to create a rectangle shape with two sides. PLease help some one.
create a drawable under drawable folder and add the belwow contents (border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<solid android:color="#color/black" />
<stroke android:width="1dip" android:color="#color/white"/>
</shape>
Now set the Background of the EditText to this draw able like :
android:background="#drawable/border"
I think the best way to do this is to create a 9-patch in PhotoShop with required border sides... there are also several other ways... depends on your design.
I have the following drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#2F2F2F"
android:endColor="#5A5A5A"
android:angle="90"
android:dither="true"
/>
</shape>
Is there anyway to start the startColor at 50% or the endColor at 50%?
Are there any links that show me all of the attributes I can apply to a gradient?
These pages show all the attributes you can apply to a gradient.
http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape
http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html
To do something in the middle like you are asking, try experimenting with the android:centerColor attribute.
Are you talking about transparency? I'm fairly certain you can just use a 8-digit color code rather than a 6-digit, the first 2 of which constitute the alpha value. So #AARRGGBB, or something like #882F2F2F.