Drawables在TabHost选项卡切换时Alpha变化

时间:2013-02-04 16:49:22

标签: android tabs android-tabhost tabwidget

当我在TabHost中的标签之间点击时,我需要更改标签的drawable的alpha。我是这样做的:

getTabHost().setOnTabChangedListener(new OnTabChangeListener() {

                        public void onTabChanged(String tabId) {
                            Activity currentActivity = getCurrentActivity();
                            Log.i("choosed activity", currentActivity.toString());
                            if (currentActivity instanceof LoginActivity) {
                                Log.i("current activity", "LoginActivity");
                                getResources().getDrawable(R.drawable.login).setAlpha(255);
                                getResources().getDrawable(R.drawable.signup).setAlpha(80);
                                getResources().getDrawable(R.drawable.close).setAlpha(80);
                            }
                            if (currentActivity instanceof RegisterActivity) { 
                                Log.i("current activity", "RegisterActivity");
                                getResources().getDrawable(R.drawable.login).setAlpha(80);
                                getResources().getDrawable(R.drawable.signup).setAlpha(255);
                                getResources().getDrawable(R.drawable.close).setAlpha(80);
                            }
});

当前活动确定成功,但只有当我翻转设备时,alpha才会发生变化。请告诉我,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

也许你应该在设置新的alpha值后尝试invalidate()