How do I achieve the following xml layout? - android-layout

Layout made by me
Layout I want to achieve
orange_hollow_fill_round_corner.xml (Custom Drawable)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="15dp" />
<stroke
android:width="1dp"
android:color="#color/orange" />
<size
android:width="80dp"
android:height="20dp" />
</shape>
I want to make custom drawable like shown below so that the it does not cut Earned Badges Text view.
Please ignore differences in corner and colors of my layout and layout that I want to achieve.

you can do it by just add background to textView (Earned Badges) this background has corner and black color by android:background="#drawable/your_custom_button" it will overlap on orange stork .
I hope it will help you .

As #noureldien mohamed way may seem viable for now but if you really want to create drawable like you mentioned you should try making vector .here is the one as per your liking.
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="326.33"
android:viewportHeight="76.25"
android:width="326.33dp"
android:height="76.25dp">
<path
android:pathData="M201.13 2h109.2c7.7 0 14 6 14 13.25V61c0 7.29 -6.3 13.25 -14 13.25H16c-7.7 0 -14 -6 -14 -13.25V15.25C2 8 8.3 2 16 2h92.42"
android:strokeColor="#FC7F2D"
android:strokeWidth="3"
android:strokeLineCap="round"
android:strokeLineJoin="round" />
OUTPUT

Related

Shape with an alternated bi-color border in android studio

I would like to create a shape to use as a background for an element, since the app has red and orange as main colors I would like to make a cool border, however I have only managed to find how to put a single color and don't really know how to do a sort of a design.
I would like to do something like this (I made this quickly in paint just a demonstration of my idea):
Shape with cool alternated border
Ok I worked on it a bit and came to a solution that isn't exactly what I was trying to do but it will be good enough I guess. This is the code to put in the xml file in the drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle"
android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<stroke
android:width="10dp"
android:color="#color/colorAccent"/>
</shape>
</item>
<item>
<shape
android:shape="rectangle"
android:padding="10dp">
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
<stroke
android:width="8dp"
android:color="#color/colorPrimary"
android:dashGap="10dp"
android:dashWidth="8dp" />
</shape>
</item>
</layer-list>
this code will produce this result:
shape with bicolor border
Hope this helps anybody

Android Studio 4.1 bordered Button loses border setting background color in kotlin code

There are numerous threads for creating a bordered button in this forum.
It works for example perfect with this xml-file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFEB3B" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#000000"/> `<!--Border-->`
</shape>
where i fail is the following:
i need 2 bordered buttons, one is yellow, the other one blue. Due to program logic I want to switch the colors, the yellow one gets blue, the blue one to yellow.
in the xml-file
<solid android:color="#FFEB3B" />`<!--Background Color-->`
is used.
In Kotlin I only find
button.setBackgroundColor(Color.YELLOW)
But I find nor button.setColor oder button.setdologColor or anything else.
Using setBackgroundColor, the color changes, but the border disappears. Which statement would keep the border?
I solved it with
punktelinks.setBackgroundResource(R.drawable.shapecolory)
in code and with resource
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFF00" />`<!--Background Color-->`
<stroke android:width="2dip" android:color="#000000"/> `<!--Border-->`
</shape>
This works (for me)

default circle ProgressBar thickness etc

I have the default circle ProgressBar:
https://i.stack.imgur.com/DlYL4.png
I would like to change the thickness, color and the corner radius (in an XML) Already, found some examples, but they don't work with the default circle.
Thank you very much!
Create an xml file in drawable folder.
Drawable XML file
progress_bar_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="360">
<shape
android:shape="ring"
android:thickness="2dp"
android:useLevel="false">
<gradient
android:type="sweep"
android:useLevel="false"
android:startColor="#ff00ff"
android:endColor="#00ffffff"
android:angle="0"/>
</shape>
</rotate>
Start color and end Color of gradient you should change according to your need.
To change the thickness of progress bar you change the thickness using android:thickness attribute of shape.
And add code to your layout xml file.
<ProgressBar
android:id="#+id/progress_bar"
android:layout_width="30dp"
android:layout_height="30dp"
android:indeterminateDrawable="#drawable/progress_bar_bg" />
android:layout_width and android:layout_height should be change according to your need.
I hope its Work for you.

Reusing a border resource with multiple background colors

I currently have the following xml file in my /res/drawable folder:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#color/transparent_white" />
<stroke
android:width="1dip"
android:color="#color/light_gray" />
</shape>
Sometimes I would like the background to be white, gray, blue etc. depending on the item I am trying to border. Is there a way to do this without creating n number of xml files where the only difference is the color of the solid attribute?
you could do this by dynamically declaring the shape and changing the color at runtime.
ShapeDrawable shapeDrawable= new ShapeDrawable();
shapeDrawable.setShape(new RectShape());
shapeDrawable.getPaint().setColor(<your color>);
((TextView) row.findViewById(<your viewid>)).setBackgroundDrawable(shapeDrawable);

Layout like Cards in android

I want to make an android layout like Google Cards,i know there is an Open Source Libraries, however i want only the Layout and the gray hex background style. I could not find information about this, how i can make this possible? im Attaching new Google maps v7 Layout so you can get the idea.
bg_card.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#CCC" />
</shape>
</item>
<item android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#FFF" />
</shape>
</item>
</layer-list>
Or just set the background of the card to #FFF and add at the bottom:
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCC" />
NOTE:
For everyone who doesn't care about using a library, you should use
a CardView from the Android support library.
Sample code.
<item name="android:windowBackground">#ffe3e3e3</item>
In your style.xml should make you happy ;-)
And for the layout, copying the card background should be enough isn't it?
We can use the LayerList as above to achieve this (OR) by using the nine patch image get same effect, we need not create nine patch image separately for this puprpose android drawable have one.
if you are using eclipse: android:background="#drawable/abc_menu_dropdown_panel_holo_light"
copy paste the above line as your View backround.
or if you are using android studio copy paste the following line:
android:background="#android:drawable/dialog_holo_light_frame"

Resources