Android SlidingTabs style tabs with round corners -


i using slidingtabs create 2 tabs. ui of tab should appear -

when first tab selected slidingtab ui

when second tab selected. slidingtab ui 2

(please note straight corners of blue rectangle)

i using following selector create ui shown above.

<selector xmlns:android="http://schemas.android.com/apk/res/android">     <!--  active tab -->     <item android:state_selected="true" android:state_focused="false"         android:state_pressed="false" android:drawable="@drawable/round_corner_rectangle" />     <!--  inactive tab -->     <item android:state_selected="false" android:state_focused="false"         android:state_pressed="false" android:drawable="@android:color/transparent" />     <!--  pressed tab -->     <item android:state_pressed="true" android:state_selected="true" android:drawable="@drawable/round_corner_rectangle" />      <item android:state_pressed="true" android:state_selected="false" android:drawable="@color/transparent" />     <!--  selected tab (using d-pad) -->     <item android:state_focused="true" android:state_selected="true"         android:state_pressed="false" android:drawable="@android:color/transparent" /> </selector> 

round_corner_rectangle's code follows-

<shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle">     <corners android:radius="5dp"/>     <solid android:color="@color/login_background" /> </shape> 

login_background dark blue color. using above code, getting following-

ui 1ui 2

i can ofcourse remove corner item round_corner_rectangle dark blue background straight instead of round. if make right side of blue rectangle straight, when other tab selected, rectangle rounded on wrong side.

what should ui shown in first image?

update:- can see code, don't have issue in creating round corners, issue having straight corners on selected tab. if add round corners, when second tab selected, corners rounded on wrong side.

ok first of create simple rectangle drawable xml. , don't worry corners going create dynamically.

tabbackground.xml

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"     android:shape="rectangle">     <solid android:color="your_color" />     <size android:height="40dp" /> </shape> 

now when changing tab. have retrive position of selected tab using listeners in selectedtabposition variable. not writing fullycode giving skeleton

if (selectedtabposition == 0) { // means first tab      gradientdrawable drawable = (gradientdrawable) getresources().getdrawable(r.drawable.tabbackground);     drawable.setcornerradii(new float[]{30,30,0,0,0,0,30,30}); // create corner radious left side  } else if (selectedtabposition == your_total_tabcount) { // menas it's last tab      gradientdrawable drawable = (gradientdrawable) getresources().getdrawable(r.drawable.tabbackground);     drawable.setcornerradii(new float[]{0,0,30,30,30,30,0,0}); // create corner radious right side  } else { // don't have worry it. used if have more 2 tab. means middle tabs      gradientdrawable drawable = (gradientdrawable) getresources().getdrawable(r.drawable.tabbackground);      drawable.setcornerradii(new float[]{0,0,0,0,0,0,0,0}); // remove corner radious  } // , @ last don't forget set drawable. 

this have tried on button click

enter image description here

enter image description here


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -