Android TabHost使View.INVISIBLE无用

时间:2012-02-21 16:22:59

标签: android

我的应用程序中有4个选项卡。首先,我想在第一个选项卡tab1中隐藏所有组件。当我第一次进入应用程序时,组件真的隐藏了。但奇怪的事情发生在这里,如果我然后点击tab2然后转到tab2,那没关系。之后,我点击返回tab1,这次,我的tab1中的所有组件再次出现。请帮助指出问题所在。这是我的代码:

public class abc extends TabActivity {

    TabHost tabHost;    

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        tabHost = getTabHost();
        LayoutInflater.from(this).inflate(R.layout.main,
                tabHost.getTabContentView(), true);
        tabHost.addTab(tabHost.newTabSpec("tab1")
                .setIndicator("",getResources().getDrawable(R.drawable.search))
                .setContent(R.id.tab1)); 

        tabHost.addTab(tabHost.newTabSpec("tab2")
                .setIndicator("",getResources().getDrawable(R.drawable.hotitem))
                .setContent(new Intent(this, tab2.class))); 

        tabHost.addTab(tabHost.newTabSpec("tab3")
                .setIndicator("",getResources().getDrawable(R.drawable.reminder))
                .setContent(new Intent(this, tab3.class)));

        tabHost.addTab(tabHost.newTabSpec("tab4")
                .setIndicator("",getResources().getDrawable(R.drawable.compass))
                .setContent(new Intent(this, tab4.class)));

        if(Variable.isLogin == 0){
            tab1 = (LinearLayout)findViewById(R.id.tab1);
            tab1.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public void onResume(){
        super.onResume();
        Log.d("log_tag", "onResume");
        if(Variable.isLogin == 0){
            tab1.setVisibility(View.INVISIBLE);
        }
    }
    @Override
    public void onPause(){
        super.onPause();
        Log.d("log_tag", "onPause");
    }
    @Override
    public void onStop(){
        super.onStop();
        Log.d("log_tag", "Stop");
    }
    @Override
    public void onRestart(){
        super.onRestart();
        Log.d("log_tag", "onRestart");
    }
    @Override
    public void onStart(){
        super.onStart();
        Log.d("log_tag", "onStart");
    }
}

0 个答案:

没有答案