Android: set the color of the pressed tab to the background color of the TableRow

I have a TabLayout. In this case, I have a table with dynamically added rows. When TableRow is selected / clicked, I want to set its background color to the "Click" or "Click" tab on the tab.

I do not want to set any static color, but I want to use the default theme color. How to get tablayout color information?

How to handle the left and right sides of tabs? This is what I get, and after setting tab_background.xml as background backgroundRsourse for all tabs: Tab bg settings

- , . , . - , , , . , tab_selected_bar_right tab_selected_bar_left. , , . int xml, @mudit.

, . . .

+3
2

. , . , . @Yugandhar, .

0

java :

( 2 , , )

TabWidget tw = getTabWidget();

View tab1View = tw.getChildAt(0);
tab1View.setBackgroundResource(R.drawable.tab_background);

View tab2View = tw.getChildAt(1);
tab2View.setBackgroundResource(R.drawable.tab_background);

tab_background.xml:

( )

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="false" android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/tab_bg" />

    <item android:state_focused="false" android:state_selected="true"
        android:state_pressed="false" android:drawable="@drawable/tab_selected" />

    <item android:state_focused="true" android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/tab_bg" />

    <item android:state_focused="true" android:state_selected="true"
        android:state_pressed="false" android:drawable="@drawable/tab_selected" />

    <item android:state_pressed="true"
        android:drawable="@drawable/tab_selected" />
</selector> 
+5

All Articles