I'm not UI designer so I can't feel xml colors enough, I want to make gradient like this:
http://t1.uccdn.com/en/images/6/5/2/img_2256_ins_45517_600.jpg
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#1f313d"
android:endColor="#2c3942"
android:angle="135"/>
</shape>
</item>
but... I think that 2 colors are not enough, how to make it similar gradieƱt to this image then? *last screen
How to create Gradient ??
Create Gradient is very easy
Right click on drawable folder and create xml file.
Create shape Tag
Inside shape tag create gradient tag
Gradient Properties........
android:startColor="put here your color"
android:endColor="put here your color"
android:centerColor="put your color here"
android:angle="45"
if you need gradient in
horizontal way put angle = "0"
vertical way put angle = "90"
corner horizontal way put angle = "45"
and opposite of corner horizontal way put angle = "135"
use this .......
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#915d5b"
android:endColor="#418c47"
android:angle="45"></gradient>
</shape>
enjoy coding.......
Or you could simply use Gradient Generator tools at AngryTools, which is much easier and fun to use.
Related
My goal is to display a circular image, and allow the user to set its foreground and background colors respectively, for example:
My attempt was to create an image asset with transparent background, then use ImageView::setColorFilter to change its foreground, and use ImageView::setBackgroundColor to set its background. The image asset looks like this:
My problem is that pixels outside of what we humans call 'border' are also transparent, so the result looks like this:
How do people usually deal with this issue? Although I was doing Android development, but any ideas or code snippets in any language are appreciated!
at the first, you must create a new drawable file and write below code for creating the circle with yellow color with blue border:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#cab816" />
<size android:width="50dp"
android:height="50dp"/>
<stroke android:width="2dp"
android:color="#color/darkBlue"/>
</shape>
and now you must set this drawable to the background of your imageview and set your image with src.
if your image covered all of this circle, use padding for decrease image size.
I want to set a transparent background. Maybe 20% of gray
but i also want to have a small part of the background being completely transparent (a rectangle or a circle in the layout):
Is that possible? later i want the rectangle (or the circle) to be moveable and scaleable.
This is easily achievable with a custom drawable like this:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:innerRadius="0dp"
android:shape="rectangle"
android:thicknessRatio="1.9"
android:useLevel="false">
<solid android:color="#android:color/transparent"/>
<stroke
android:width="125dp"
android:color="#CC000000"/>
</shape>
When you overlay that drawable on top of an image the results would looks something like this:
By creating that drawable dynamically in code you can adjust it at runtime. For example:
ShapeDrawable drawable = new ShapeDrawable(new RectShape());
drawable.getPaint().setColor(0xCC000000);
drawable.getPaint().setStyle(Paint.Style.STROKE);
drawable.getPaint().setStrokeWidth(dpToPixel(125.0f));
someView.setBackground(drawable);
You can influence the shape of the hole in the middle by combining multiple layers in a LayerDrawable.
You can also influence the general shape of the hole by setting the android:shape tag of the <shape /> element in the custom drawable.
I am new to android. I want to draw a custom shape in android. When someone chooses a date(via date picker) I want to display the result in a square box rather than the regular way.How do I achieve this?
You can use a textview to show the selected date. Since you seem to know the coding for that, I focus on the design you can apply for your textview.
By default, a textview has a rectangular shape with sharp edges and points, but you can achieve a rounded-corner textview using a style , like this one :
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#color/red"/>
<corners android:radius="7dp" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>
<solid android:color="#color/white"/></shape>
The corners tag, is responsible for the rounded corners, you can tweak th radius to make more or less rounded.
Stroke tag, defines the width and color of the border for the textbox.
and Solid tag determines the bakcground color of the view.
In order to use this style, you should save it as an XML file and save it in drawable folder (normally drawable-hdpi will do). Then , in your tetxview or edittext you should set the background property as the following :
android:background="#drawable/thesavedxmlfile"
how can i make a shadow for round corners? I tried it with views for the bottom, right an the corner, but that works not really :D
I tried this xml for the corner:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#404040"
android:centerColor="#DBDBDB"
android:endColor="#color/shadow_end"
android:angle="315"
>
</gradient>
<corners
android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
Is it good to use views for shadows? What you are using?
Thanks for help :)
You can simply draw a 9-patch image with Photoshop drawing the shadows and put it into the drawable folders and set this in your View in xml:
android:background="#drawable/your_9patch_image"
I always do it by using Photoshop. For more details see this: Draw 9-patch
Or you can check in the default Android Studio drawables and see if there's one that you like. Check my answer here: my answer
Im trying to achieve a component to make custom shadows to buttons or other components, i know that it will be easier with a 9patch or a png with the shadow, but i want to change it color and size programmatically also in its states (pressed,etc), so i decided to try with 9 images, all in XML so the shadow shades start its gradient from the side of the component.
<!-- Left Shadow layer -->
<item>
<shape android:shape="rectangle" >
<gradient
android:angle="0"
android:endColor="#FFFF0000"
android:startColor="#00FF0000" />
</shape>
</item>
It looks good, the problem is on the corners and with the android:gradientRadius parameter now its set to a fixed size, but in the contextual help is said that can be set in a percentage of the base size 10% or parent size 10%p, what i want its to set a 100%p radius so the gradient will always go from the main color and disappear in the edge of the square.
-- EDIT --
The android doc about gradientRadius gradientRadius
<shape android:shape="rectangle" >
<gradient
android:endColor="#00FF0000"
android:startColor="#FFFF0000"
android:gradientRadius="18"
android:centerX="100%"
android:centerY="100%"
android:type="radial" />
</shape>
And thats where im now :( i do not know how can i set this size to fit its parent view.
Any help will be appreciated, when im finished with the component i will put the code in an answer :) so typical buttons can have customizable shadows in xml.
An image of the deserved component.
--Edit--
Im still interested in this :) no one has a clue?
I think you should give up with xml and implement drawable in code.
When you extend Drawable class you can get size as rectangle with getBounds(). Also you can dynamicaly recalculate in onBoundsChange method.
You can also easily construct gradients and use them in Paint object (setShader method)