Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Tab layout becomes invisible when come back from other activity
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Log.d("prabhu", "In tab .....");
- context = this;
- tabHost = (TabHost)findViewById(android.R.id.tabhost);
- tabHost.setup();
- /* TabSpec used to create a new tab.
- * By using TabSpec only we can able to setContent to the tab.
- * By using TabSpec setIndicator() we can set name to tab. */
- /* tid1 is firstTabSpec Id. Its used to access outside. */
- TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
- TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
- TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
- TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
- /* TabSpec setContent() is used to set content for a particular tab. */
- Intent t1 = new Intent(this,Activity1.class);
- firstTabSpec.setContent(t1);
- firstTabSpec.setIndicator("Activity1");
- Intent t2 = new Intent(this,Activity2.class);
- secondTabSpec.setContent(t2);
- secondTabSpec.setIndicator("Activity2");
- Intent t3 = new Intent(this,Activity3.class);
- thirdTabSpec.setContent(t3);
- thirdTabSpec.setIndicator("Activity3");
- Intent t4 = new Intent(this,Activity4.class);
- fourthTabSpec.setContent(t4);
- fourthTabSpec.setIndicator("Activity4");
- /* Add tabSpec to the TabHost to display. */
- tabHost.addTab(firstTabSpec);
- tabHost.addTab(secondTabSpec);
- tabHost.addTab(thirdTabSpec);
- tabHost.addTab(fourthTabSpec);
- tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =45;
- tabHost.getTabWidget().getChildAt(1).getLayoutParams().height =45;
- tabHost.getTabWidget().getChildAt(2).getLayoutParams().height =45;
- tabHost.getTabWidget().getChildAt(3).getLayoutParams().height =45;
- for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
- {
- tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#AEDB00")); //unselected
- }
- tabHost.setOnTabChangedListener(new OnTabChangeListener(){
- public void onTabChanged(String tabId) {
- for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
- {
- tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#AEDB00")); //unselected
- }
- tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#B33E5D")); // selected
- }});
Add Comment
Please, Sign In to add comment