android自定义TabHost点击效果

昨天同事请帮忙实现一个小功能,今天中午做了下,即让TabHost的点击可以像ImageButton一样丰富。直接上代码:
tabHost.getTabWidget()
                .getChildTabViewAt(0) 
                .setOnTouchListener(new OnTouchListener()
                {
                    
                    @Override
                    public boolean onTouch(View v, MotionEvent event)
                    {
                        ViewGroup view = (ViewGroup) tabHost.getTabWidget()
                                .getChildTabViewAt(0);
                        switch (event.getAction())
                        {
                            case MotionEvent.ACTION_DOWN:

                                ((ImageView) (view.getChildAt(0))).setImageDrawable(res.getDrawable(R.drawable.ff));
                                break;
                            
                            case MotionEvent.ACTION_UP:
                                ((ImageView) (view.getChildAt(0))).setImageDrawable(res.getDrawable(R.drawable.ic_launcher));
                                break;
                        }
                        
                        return false;
                    }
                });

你可能感兴趣的:(android,android,up)