Open jianinz opened 10 years ago
update: it works with android:state_pressed="true"
, but if i would like to customize the color of current active tab, android:state_selected="true"
seems does not work, does anybody know what is wrong here?
@jianinz I think selected is used when navigating with a cursor (eg d-pad). Check the regular item background on how to set a selector: https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/item_background.xml
Thanks for pointing it out @mpost.
@jianinz
I make some change in lib
...
private View preTab;
...
private void addTab(final int position, final View tab) {
if(position == 0){
tab.setSelected(true);
preTab = tab;
}
tab.setFocusable(true);
tab.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
pager.setCurrentItem(position);
tab.setSelected(true);
if(preTab != null) preTab.setSelected(false);
preTab = tab;
}
});
tab.setPadding(tabPadding, 0, tabPadding, 0);
tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}
and now i can add state selected
<item android:state_selected="true" android:drawable="@drawable/check_on"/>
sorry author of this lib? but i can w8 ;)
Hi guys,
I am having a trouble when setting different background for each tab with
StateListDrawable
, here is how my xml looks like/res/drawable/selector_tab.xml
where pressed and normal state would have different color reference back to
/res/values/colors.xml
The normal color state will always be set, but not selected neither pressed state color will be set. Am i missing something?