Guest User

Untitled

a guest
Aug 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. Tab layout becomes invisible when come back from other activity
  2. public void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. setContentView(R.layout.main);
  5. Log.d("prabhu", "In tab .....");
  6. context = this;
  7. tabHost = (TabHost)findViewById(android.R.id.tabhost);
  8. tabHost.setup();
  9.  
  10. /* TabSpec used to create a new tab.
  11. * By using TabSpec only we can able to setContent to the tab.
  12. * By using TabSpec setIndicator() we can set name to tab. */
  13.  
  14. /* tid1 is firstTabSpec Id. Its used to access outside. */
  15. TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
  16. TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
  17. TabSpec thirdTabSpec = tabHost.newTabSpec("tid3");
  18. TabSpec fourthTabSpec = tabHost.newTabSpec("tid4");
  19.  
  20. /* TabSpec setContent() is used to set content for a particular tab. */
  21. Intent t1 = new Intent(this,Activity1.class);
  22. firstTabSpec.setContent(t1);
  23. firstTabSpec.setIndicator("Activity1");
  24.  
  25. Intent t2 = new Intent(this,Activity2.class);
  26. secondTabSpec.setContent(t2);
  27. secondTabSpec.setIndicator("Activity2");
  28.  
  29. Intent t3 = new Intent(this,Activity3.class);
  30. thirdTabSpec.setContent(t3);
  31. thirdTabSpec.setIndicator("Activity3");
  32.  
  33.  
  34.  
  35. Intent t4 = new Intent(this,Activity4.class);
  36. fourthTabSpec.setContent(t4);
  37. fourthTabSpec.setIndicator("Activity4");
  38.  
  39. /* Add tabSpec to the TabHost to display. */
  40. tabHost.addTab(firstTabSpec);
  41. tabHost.addTab(secondTabSpec);
  42. tabHost.addTab(thirdTabSpec);
  43. tabHost.addTab(fourthTabSpec);
  44.  
  45. tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =45;
  46. tabHost.getTabWidget().getChildAt(1).getLayoutParams().height =45;
  47. tabHost.getTabWidget().getChildAt(2).getLayoutParams().height =45;
  48. tabHost.getTabWidget().getChildAt(3).getLayoutParams().height =45;
  49.  
  50. for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
  51. {
  52. tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#AEDB00")); //unselected
  53. }
  54.  
  55. tabHost.setOnTabChangedListener(new OnTabChangeListener(){
  56.  
  57. public void onTabChanged(String tabId) {
  58. for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
  59. {
  60. tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#AEDB00")); //unselected
  61. }
  62. tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#B33E5D")); // selected
  63.  
  64. }});
Add Comment
Please, Sign In to add comment