Android TabLayout With Border On Top - android

I read documentation about TabLayout for add property to make border on top of TabLayout but I didn't find it anywhere in documentation.
So I want some trick to make TabLayout have border on top (or maybe at bottom).

Solved with this drawable xml:
<?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="#FFDDDDDD" />
<solid android:color="#FFFFFFFF" />
</shape>
</item>
<item
android:top="1dp">
<shape android:shape="rectangle">
<stroke
android:width="1dp"
android:color="#FFFFFFFF" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
and set into tablayout attribute/property:
android:background="#drawable/drawableName"

Use a custom ViewPager Strip.
Try this: https://github.com/ogaclejapan/SmartTabLayout

you have to create a drawable, then call in this way
android:background="#drawable/yourShapeHere"
the drawable is looks like:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke android:width="2dp" android:color="#515151"/>
<corners android:radius="3dp" />
<padding android:left="10dp" android:top="5dp" />
</shape>

Related

How to achieve custom shape match parent?

I created custom shape in XML:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item>
<shape android:shape="rectangle">
<size android:width="160dp"/>
<size android:height="30dp"/>
<solid android:color="#color/white"/>
<padding android:right="15dp"/>
<stroke android:width="1dp" android:color="#color/main_color"/>
<corners android:radius="15dp"/>
</shape>
</item>
<item
android:drawable="#drawable/down_arrow_red"
android:width="10dp"
android:height="6dp"
android:gravity="center|right"/>
</layer-list>
</item>
</selector>
Since match parent wasn't allowed while defining of width and height, I am worried how this shape will look like on different size screens. How to make this shape match parent screen? Thanks!
I think what you want to ask is about sizing.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<item>
<shape
android:layout_width="match_parent"
android:shape="rectangle">
<size android:height="30dp" />
<solid android:color="#color/white" />
<padding android:right="15dp" />
<stroke
android:width="1dp"
android:color="#color/teal_200" />
<corners android:radius="15dp" />
</shape>
</item>
<item
android:width="10dp"
android:height="6dp"
android:drawable="#android:drawable/arrow_down_float"
android:gravity="center|right" />
</layer-list>

How to set up only circle size(in xml)?

I want to set up circle size, but I don't want resize other elements in layer list.
I have this code:
<?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/drawer_color" />
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#1b2727"
android:centerColor="#1a2a29"
android:startColor="#154440"
android:type="linear"
android:angle="90"/>
<size
android:height="600dp"
android:width="600dp" />
<stroke
android:width="3dip"
android:color="#color/drawer_ring_color" />
</shape>
</item>
</layer-list>
What I found:
And what I want to see:
How to do that?
Thanks!
Unfortunately this do not works this way, your drawable will take the size of view where you use that drawable.
Try to set padding in your code.
<item>
<shape android:shape="rectangle">
<solid android:color="#color/drawer_color" />
<padding
android:left="10dp"
android:top="100dp"
android:right="10dp"
android:bottom="100dp" />
</shape>
</item>

How to create round corner tab in android like this?

is there any body know how to create a round corner tab like this:
Expected Tabs:
Coming Tabs:
hope you can tell me.Thank you.
#Vinodh I use Tablayout with ViewPager. I set a style to the Tablayout and set the tabBackground property with a selector like this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape>
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
<solid android:color="#fff"/>
</shape>
</item>
<item>
<layer-list>
<item>
<shape>
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
<solid android:color="#color/white"/>
</shape>
</item>
<item>
<shape>
<corners android:radius="8dp"/>
<solid android:color="#000"/>
</shape>
</item>
</layer-list>
</item>
And set the background of Tablayout:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
<solid android:color="#000"/>
Try below shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="14dp"
/>
<gradient
android:angle="45"
android:centerX="35%"
android:centerColor="#000000"
android:startColor="#000000"
android:endColor="#000000"
android:type="linear"
/>
<padding
android:left="0dp"
android:top="0dp"
android:right="0dp"
android:bottom="0dp"
/>
<size
android:width="270dp"
android:height="60dp"
/>
<stroke
android:width="3dp"
android:color="#000000"
/>
</shape>
If you want to change tab layout make custom background in drawable and give rounded corner in both selected and selected tab
In Your Activity/Fragment
I set background in tablayout so you can make background as per your requirement
adding only customization code for brevity
val tabCount: Int = images_videos_tab_layout.tabCount
for (i in 0 until tabCount) {
val tabView: View = (images_videos_tab_layout.getChildAt(0) as ViewGroup).getChildAt(i)
tabView.requestLayout()
ViewCompat.setBackground(tabView,setImageButtonStateNew(requireContext()));
ViewCompat.setPaddingRelative(tabView, tabView.paddingStart, tabView.paddingTop, tabView.paddingEnd, tabView.paddingBottom);
}
fun setImageButtonStateNew(mContext: Context): StateListDrawable {
val states = StateListDrawable()
states.addState(intArrayOf(android.R.attr.state_selected), ContextCompat.getDrawable(mContext, R.drawable.tab_bg_normal_blue))
states.addState(intArrayOf(-android.R.attr.state_selected), ContextCompat.getDrawable(mContext, R.drawable.tab_bg_normal))
return states
}
In Drawable
1.tab_bg_normal
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/your_unselected_tab_color" />
<corners android:radius="25dp" />
</shape>
2.tab_bg_normal_blue
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#color/baseThemeColor" />
<corners android:radius="25dp" />
</shape>
3.tabview_bg
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="25dp"/>
<stroke android:color="#color/baseThemeColor" android:width="1dp"/>
<solid android:color="#00000000"/>
</shape>

How to add a drop shadow to a Rectangular Shape in Android

I am developing an Android App in which I need to use a Rectangular shape which should have a drop_shadow. I have designed a rectangular shape but somehow i am not able to add a drop shadow to it on (right and left sides).
P.S.: this rectangular shape is added as a background attribute.
If this type of Question is already been answered then please provide the links here.
THANK YOU IN ADVANCE!!!!
Code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke
android:width="1dp"
android:color="#000000" />
<corners
android:radius="10dp" >
</corners>
</shape>
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="#CABBBBBB"/>
<corners android:radius="2dp" />
</shape>
</item>
<item
android:left="0dp"
android:right="1dp"
android:top="0dp"
android:bottom="2dp">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
<corners android:radius="1dp" />
</shape>
</item>
</layer-list>

Create Drawable with borders completely programmatically

I have the following xml:
<?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="#000000" />
<solid android:color="#000000" />
</shape>
</item>
<item android:top="0dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#414141" />
<solid android:color="#414141" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#2C2C2C" />
<solid android:color="#2C2C2C" />
</shape>
</item>
</layer-list>
This does exactly what I want but I can't use it. I want to change the colors of the three layers on runtime so I have to do this completely programmatically. I know I have to use LayerDrawable but I don't know how to implement the equivalent of android:top and android:bottom. Can somebody help me?
ImageView imageView1 = (ImageView) findViewById(R.id.imgView1);
((GradientDrawable ) imageView1.getBackground()).setColorFilter(
Color.RED, PorterDuff.Mode.SRC_ATOP);

Categories

Resources