开发者

How to change border color (shape) on select in Android?

开发者 https://www.devze.com 2023-01-11 17:04 出处:网络
I\'ve a border set around a drawable using LinearLayout (bg: rounded rectangle). The drawable and the border is used as a tab view. I\'d like to change the border color of the tab when it is selected

I've a border set around a drawable using LinearLayout (bg: rounded rectangle).

The drawable and the border is used as a tab view. I'd like to change the border color of the tab when it is selected.

How can I do this?

Color state list doesn't seem to work as the view being selected is not the shape (i.e border) but the tab. Drawable state list doesn't seem to work either as I'm trying to swivel between views, not drawables. Moreover, I can't find any "onSelectedListener" of the sor开发者_JAVA技巧t...


You need to make an OnClickListener to handle clicks, and get it to change the appropriate background:

private OnClickListener tabClick(Context mContext){
  @Override
  onClick(View v){
    v.setBackgroundResource(R.drawable.active);
  }
}
myTab.setOnClickListener(tabClick);


The solution is to call setOnTabChangeListener in the TabHost and then change everything manually.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号