android-shape

Android: How to make a drawable with a multicolor gradient?

冷暖自知 提交于 2019-12-12 10:09:49
问题 I made this: ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(0, 0, width, height, new int[]{ 0xF44336, 0xFFB74D, 0xFFE082, 0xAED581, 0x4CAF50, 0xAED581, 0xFFE082, 0xFFB74D, 0xF44336}, new float[]{ 0, 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f}, Shader.TileMode.REPEAT); return linearGradient; } }; PaintDrawable paint = new PaintDrawable();

How to show only top and bottom border

半城伤御伤魂 提交于 2019-12-12 07:27:27
问题 This is my XML code which works fine, the only problem is it's showing border on all four sides while I want only to show border on the top and on the bottom only. How can I do that? <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#FFFFFF" /> <stroke android:width="3dip" android:color="#B1BCBE" /> <padding android:bottom="0dip" android:left="0dip" android:right="0dip" android:top="0dip" /> </shape> 回答1: Try the

Android: how to create shape with skewed two-tone color?

房东的猫 提交于 2019-12-12 02:31:42
问题 I am attempting to create a drawable shape that will become the background of a search bar. I know how to create a rectangle with two colors but I do not know how to tilt the color at an angle, like in the second image. Can someone help me with this? Thanks. 回答1: Take a Toolbar...code is here... <android.support.v7.widget.Toolbar android:layout_width="500dp" android:layout_height="wrap_content" android:background="@drawable/custom_background" /> create a drawable res file custom_background

How to Draw Arrowline in android.graphics.Path with correct configerations

醉酒当歌 提交于 2019-12-11 22:21:58
问题 What I have Tried: I'm trying to display the arrow line with following code Path mArrowPath=new Paint();; mArrowPath.rewind(); mArrowPath.moveTo(0, mHeight / 2); mArrowPath.lineTo(mWidth / 2, 0); mArrowPath.lineTo(mWidth, mHeight / 2); mArrowPath.lineTo(mWidth * 3 / 4, mHeight / 2); mArrowPath.lineTo(mWidth * 3 / 4, mHeight); mArrowPath.lineTo(mWidth / 4, mHeight); mArrowPath.lineTo(mWidth / 4, mHeight / 2); mArrowPath.lineTo(0, mHeight / 2); Shape pathshap = new PathShape(mArrowP,maxWidth

Unable to understand layer-list

廉价感情. 提交于 2019-12-11 11:14:02
问题 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:top="4dp" android:right="4dp" android:bottom="4dp" android:left="4dp"> <shape android:shape="oval"> <solid android:color="#ff0000" /> </shape> </item> <item> <shape android:shape="oval"> <stroke android:width="2dp" android:color="#ff0000"/> </shape> </item> </layer-list> taken from here: https://stackoverflow.com/a/36003935/6007737 How is it giving me a ring shape? How

Icon image in circle shape is blurry

半腔热情 提交于 2019-12-11 10:17:18
问题 I have created circle shape drawables that contain png icons. As per the Android Material guidelines the diameter of the circle is 40dp and the icon is 24dp. Initially I did not set any values for left, right, top and bottom as I assumed the internal icon item would stay 24dp. However, it resizes. I then tried using width and height properties to force it to 24dp, which appeared to work in the preview in AS but had no effect on the tablet. Finally I set the values of top, bottom, left and

Android shape triangle with border

試著忘記壹切 提交于 2019-12-08 13:21:55
问题 I've created triangle shape as in code below: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <rotate android:fromDegrees="45" android:toDegrees="45" android:pivotX="13%" android:pivotY="-40%" > <shape android:shape="rectangle" > <stroke android:color="#000000" android:width="1dp"/> <solid android:color="#000000" /> </shape> </rotate> </item> </layer-list> How can I make border color of the triangle different from the rest

How to create a custom shape for a Button

此生再无相见时 提交于 2019-12-08 03:12:26
问题 How to create a custom shape for a Button? Can I set different colors to button background colors for many conditions.Any help will be appreciated.Thanks. 回答1: How to create a custom shape for a Button? Create a test.xml file in drawable and add code: <?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/one"> //<---- id is must for color change <shape android:shape="rectangle"> <size android:width="150dp"

How to create a custom shape for a Button

谁都会走 提交于 2019-12-06 15:27:36
How to create a custom shape for a Button? Can I set different colors to button background colors for many conditions.Any help will be appreciated.Thanks. How to create a custom shape for a Button? Create a test.xml file in drawable and add code: <?xml version="1.0" encoding="UTF-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/one"> //<---- id is must for color change <shape android:shape="rectangle"> <size android:width="150dp" android:height="40dp" /> <solid android:color="@color/colorPrimary" /> <corners android:radius="10dp"/> //<----

Android: How to make a drawable with a multicolor gradient?

一个人想着一个人 提交于 2019-12-06 10:31:59
I made this: ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { LinearGradient linearGradient = new LinearGradient(0, 0, width, height, new int[]{ 0xF44336, 0xFFB74D, 0xFFE082, 0xAED581, 0x4CAF50, 0xAED581, 0xFFE082, 0xFFB74D, 0xF44336}, new float[]{ 0, 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.75f, 0.875f, 1.0f}, Shader.TileMode.REPEAT); return linearGradient; } }; PaintDrawable paint = new PaintDrawable(); paint.setShape(new RectShape()); paint.setShaderFactory(shaderFactory); But I can't see anything when I