开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜