Need Help for TabHost Design - android

I need My TabHost Look like That First One.
Xml file code for Corner is :
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
<gradient
android:startColor="#88a9a9a9"
android:endColor="#000"
android:gradientRadius="400"
android:angle="270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#8858585a"
android:endColor="#88a9a9a9"/>
<corners
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
</item></selector>
Java code line :
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.roundcorner);`

Try this way,
for left side First one :-
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"/>
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
<stroke android:width="3px" android:color="#color/black" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"/>
<stroke android:width="5px" android:color="#color/black" />
</shape>
</item>
Right side Last one :-
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"/>
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<corners
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"/>
<stroke android:width="5px" android:color="#color/black" />
</shape>
</item></selector>
for center
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<gradient
android:startColor="#880f0f10"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#CCCCCC"
android:centerColor="#CCCCCC"
android:endColor="#CCCCCC"/>
<stroke android:width="5px" android:color="#color/black" />
</shape>
</item></selector>
and in Java
mTabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.roundcorner_tab_left);
mTabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.roundcorner_tab_center);
mTabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.roundcorner_tab_right);

Related

drawing images with layer-lists for android

I have been trying to create a vector similar to this image as an android drawable XML but I have been having a few issues.
I am trying to create it as a layer-list so I can have several primitives (a circle and 4 rectangles with rounded corners to act as a semi-circle).
here is my XML code for the drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:right="0dp" android:left="0dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="-80dp" android:left="0dp" android:height="20dp" android:width="20dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:right="00dp" android:left="00dp" android:height="40dp" android:width="40dp">
<shape android:shape="oval">
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>
So the problem is I can't get them to spread out as I want them. At the moment they're all on top of each other. When I try to resize one of them, they all adopt that same size for some reason, making impossible to create the semi-circles. Also when I try to move them with android:top and the like, it would drag the others with it so I am kind of lost on how I am supposed to create the shape I'm looking for.
Any help is appreciated.
I had modified your sample , hope this will help you
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:gravity="left|center_vertical" android:right="35dp">
<shape
android:shape="rectangle">
<size android:height="10dp"
android:width="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
</item>
<item android:gravity="right|center_vertical" android:left="35dp">
<shape
android:shape="rectangle">
<size android:width="10dp"
android:height="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:bottomRightRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:gravity="top|center_horizontal" android:bottom="35dp">
<shape
android:shape="rectangle">
<size android:width="10dp" android:height="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:topRightRadius="10dp"
android:topLeftRadius="10dp"/>
</shape>
</item>
<item android:gravity="bottom|center_horizontal" android:top="35dp">
<shape android:shape="rectangle">
<size android:height="10dp"
android:width="10dp"/>
<solid android:color="#2962FF"/>
<corners
android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"/>
</shape>
</item>
<item android:gravity="center_horizontal|center_vertical">
<shape android:shape="oval">
<size android:height="20dp"
android:width="20dp"/>
<solid android:color="#000000"/>
</shape>
</item>
</layer-list>

Not all items in layer-list are showing up

I'm trying to implement a view like what's in this link here: https://imgur.com/a/6b75AMp
This is the layer-list I'm using:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesLightGreen"/>
</shape>
</item>
<item android:left="8dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesBackground"/>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
// The width and color of the border
<stroke
android:width="1dp"
android:color="#3C341F" />
// The desired corner radius. reduce it to keep it less rounded
<corners android:radius="10dp" />
<solid
android:color="#F0ECE0"
/>
</shape>
</item>
</layer-list>
However, the border doesn't show up. If I play around with the order of the items--for example, if I make the vertical stripe the last item--then the border might show up, but the vertical stripe won't. How do I get everything in the layer-list to show up properly?
try the following code you will get a hint
<?xml version="1.0" encoding="utf-8"?>
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesLightGreen" />
</shape>
</item>
<item android:left="4dp" android:top="4dp" android:right="4dp" android:bottom="4dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/HobbesBackground" />
</shape>
</item>
<item android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#3C341F" />
<corners android:radius="10dp" />
<solid android:color="#F0ECE0" />
</shape>
</item>
I have modified some of your code, use it and chech the output.
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/colorPrimary"/>
</shape>
</item>
<item android:left="8dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="#color/colorAccent"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<stroke android:color="#000000" android:width="2dp"/>
</shape>
</item>

How can I draw this border?

How can I draw this gradient border(border is fade out to transparent) and radial gradient background?
My code :
Drawable/bg.xml
Radial gradient code is here
Drawable/border.xml
<item>
<shape android:shape="rectangle">
<solid android:color="#android:color/holo_blue_light"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:left="3dp" android:right="3dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:height="5dp" android:left="30dp" android:right="30dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="200dp"/>
<gradient android:endColor="#color/transparent"
android:centerColor="#color/white"
android:startColor="#color/transparent"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:endColor="#color/white"
android:startColor="#android:color/transparent"
android:angle="-90" />
</shape>
</item>
I want this result :
<?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="#android:color/holo_blue_light"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:left="3dp" android:right="3dp" android:top="2dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<corners android:topLeftRadius="100dp" android:topRightRadius="100dp"/>
</shape>
</item>
<item android:width="40dp" android:left="70dp" android:right="200dp">
<shape android:shape="rectangle">
<solid android:color="#color/colorPrimary"/>
<gradient android:endColor="#color/white"
android:startColor="#color/transparent"/>
</shape>
</item>
<item android:width="40dp" android:left="240dp" android:right="20dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
<gradient android:endColor="#color/transparent"
android:startColor="#color/white"/>
</shape>
</item>
<item android:left="110dp" android:right="120dp">
<shape android:shape="rectangle">
<solid android:color="#color/white"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient android:endColor="#color/white"
android:startColor="#color/transparent"
android:angle="-90" />
</shape>
</item>
</layer-list>
Create this rectangle.xml file inside the drawable folder.
Copy this code into it.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="270"
android:endColor="#000000"
android:startColor="#FFFFFF" />
<corners android:radius="10dp" />
<padding
android:bottom="5dp"
android:left="5dp"
android:right="5dp"
android:top="5dp" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#af25e1" />
<corners android:radius="10dp" />
<size
android:width="250dp"
android:height="150dp" />
</shape>
</item>
</layer-list>
and set it as the background to your container.
You can change it according to your needs
Hope it works for you.

how to shape the border on the left of this textview?

I've seen it in an iOS app:
and I want to implement a TextView like this in my Android app. So I've made this drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#fff"/>
<stroke android:width="1dp"
android:color="#color/colorPrimary" />
<padding android:left="5dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
</shape>
but I don't know how to make the blue color on the left.
Anyone could help me?
Thanks
You can try this :
<?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="#FF0000"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:left="5dp"
>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>
try this
<?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="#FF0000" />
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
</layer-list>
Based on #Er. Joshi answers, I have found this solution that works good:
<?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="#color/blueButton"/>
<corners
android:bottomLeftRadius="10dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="10dp"/>
</shape>
</item>
<item android:left="5dp">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp"
android:color="#BDBDBD" />
<padding android:left="10dp"
android:top="5dp"
android:right="5dp"
android:bottom="5dp"/>
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="5dp"/>
</shape>
</item>
</layer-list>

Android: writing drawables in xml

I need to create some drawables that look like image below, is there a way to do this in xml?
Edit:
I have got this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#color/darker_gray" />
<corners android:radius="6dp" />
</shape>
</item>
<item
android:bottom="3dp">
<shape android:shape="rectangle">
<solid android:color="#color/dark_gray" />
<corners android:radius="6dp" />
</shape>
</item>
</layer-list>
it's the same like on the picture without that blue corner and I have no idea how to do that diagonal shape. Now I'm using 9 patch, but since all my other buttons are in xml, I was just wondering if there is some way to write this also in xml
Try this code, i guess this is what you want:
draw.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#333333" />
<solid android:color="#333333" />
<padding android:bottom="3dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#000000" />
<solid android:color="#000000" />
<padding android:bottom="1dp"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="-40%"
android:pivotY="87%" >
<shape
android:shape="rectangle" >
<size android:width="50dp"
android:height="50dp"/>
<stroke android:color="#android:color/transparent" android:width="0dp"/>
<solid
android:color="#android:color/holo_blue_light" />
<corners android:radius="5dp"/>
</shape>
</rotate>
</item>
<item>
<shape
android:shape="rectangle">
<size android:width="100dp"
android:height="60dp"/>
<stroke android:width="2dp" android:color="#android:color/transparent" />
<solid android:color="#android:color/transparent" />
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and in your layout file
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerInParent="true"
android:background="#drawable/draw" >
</RelativeLayout>
You should use layer list to combine multiple drawables below is an example.
You should also check this very complete guide to android drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#585858" />
<solid android:color="#FF9009" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="10dp" android:top="20dp" android:bottom="20dp" android:right="150dp">
<shape
android:shape="oval">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#118C4E" />
<padding android:bottom="1dp"/>
</shape>
</item>
<item android:left="150dp" android:top="20dp" android:bottom="20dp" android:right="10dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#ffffff" />
<solid android:color="#C1E1A6" />
<padding android:bottom="1dp"/>
</shape>
</item>
</layer-list>

Categories

Resources