I've created a button, when it's clicked, it's like the picture below.
For now, it's an image created with Gimp and 9-patch. It works, but I want to know if there is a way to create the same image with a Shape in XML (only the blue part in the middle). So in the future, I can change for example the color very easily.
Thanks in advance.
Edit :
I tried something :
<item >
<shape android:shape="rectangle">
<solid android:color="#color/blue1"/>
</shape>
</item>
<item>
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<solid
android:color="#android:color/transparent" />
</shape>
</rotate>
</item>
But, of course, it doesn't work. The transparent triangle just show the blue rectangle in the background. Maybe with two triangle and one square, but i'm really weak in android shape system.
Related
I know the solid color and also the corner section but
I want to know how can I fill color of the corner
Try using stroke in your layout file. stroke can give you the border colour and width.
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:color="#color/yourcolour"
android:width="4dp"
/>
//Other adjustments
</shape>
Let me know if this is what you were looking for
Or if you want something like in your image try the below
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_red_dark"/>
<stroke android:color="#android:color/black"
android:width="10dp"
/>
</shape>
</item>
<item >
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_blue_bright"/>
<stroke android:color="#android:color/black"
android:width="10dp"
/>
<corners android:bottomLeftRadius="150dp"/>
</shape>
</item>
</layer-list>
It seems you talking about that red colour on above image.
In that case, there is no property which give you such result.
You need to make it logically., Like take 2 views with diff background,
Red background with black colour stroke.
Sky background overlaping on 1st red view.
And simply make top view background as rounded with black color stroke. It will provide you the desired design layout.
Make sure you give same stroke to both view so that itlook to be same.
Happy coding.
I need to create a speech bubble background for an icons container like the white one in this image:
Required Appearance
I decided to use a drawable xml rather than a 9 patch image, so I can control of the rounded corner radii in my code. So, with the help of this answer to a related question, I have created the following xml:
bg_icons_container.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="0dp"
android:top="27dp"> <!-- How to make this 50% of height? -->
<rotate
android:fromDegrees="-45"
android:toDegrees="0"
android:pivotX="0%"
android:pivotY="0%"> <!-- How to make the triangle more acute? -->
<shape
android:shape="rectangle" >
<solid
android:color="#color/white"/>
</shape>
</rotate>
</item>
<item
android:left="10dp">
<shape
android:shape="rectangle">
<solid
android:color="#color/white"/>
<corners
android:radius="#dimen/border_radius_small"/>
</shape>
</item>
</layer-list>
This results in:
Actual Apperance (enlarged)
My problem is that the triangular part of the drawable is too wide. How can I make it more acute? (My minSdkVersion is 16, so I cannot use android_width on the first item to try and stretch it.)
Also, I am having to hard code android:top of the first item to 27dp. Is it possible to make this 50%, so it will correctly adjust when the height of the drawable changes?
I am trying to create a chat bubble design with android drawables
My design idea was the following:
What I currently have, but what I don't like is that:
The code is the following:
<layer-list>
<item
android:right="1dp"
android:top="12dp">
<rotate
android:fromDegrees="45"
android:pivotX="100%"
android:pivotY="0%"
android:toDegrees="0">
<shape android:shape="rectangle">
<solid android:color="?attr/message_out_color" />
<stroke
android:width="1px"
android:color="#color/colorFakeShadow" />
</shape>
</rotate>
</item>
<item
android:right="8dp"
android:top="1dp">
<shape android:shape="rectangle">
<solid android:color="?attr/message_out_color" />
</shape>
</item>
</layer-list>
I tried to use the corner tag with a high radius, but that didn't result in what I imagined. Another idea was to use two ovals as that is how I've done my design idea in Paint.NET, but I didn't manage to position the ovals right. Is my idea possible to create with android drawables and if so how?
UPDATE: When I add <corners android:radius="50dp" /> it looks like this
But as you can see, it is too round, it doesn't look like my image (the first one in this post).
UPDATE 2: I cannot use 9 patch drawables, because these message bubbles have to scale in all directions, and also I need a <ripple> on the shape because the user can click on my message bubble, which can't be done with a 9 patch.
Thanks in advance!
The solutions I have found over internet cuts the rectangle but I am having like half of it without nothing and wasting space.
For example:
<?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="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#android:color/transparent" android:width="10dp"/>
<solid
android:color="#color/black" />
</shape>
</rotate>
</item>
</layer-list>
This code creates a triangle, but I have a lot of space wasted, look at the image:
I want to create a triangle that "fills" the image view. Something like this:
Not necessarily has to be equilateral. Any ideas?
Well, if it is okay for you to create the shape in java , you can do it by extending the Drawable class in Android. See this
I a created triangle shape following this post
<?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="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<stroke android:color="#color/transparent" android:width="10dp"/>
<solid
android:color="#color/your_color_here" />
</shape>
</rotate>
</item>
But I have not been able to incline it towards the right or the left.
Any help is appreciated.
Thanks
I think you could create this layout by overlaying different shapes one after another like it is shown in the selected for best answer in this question Android: Drawing custom shapes First <item> could be your rectangle and then you could use one rectangle and one triangle for the pointer