-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
38 lines (28 loc) · 1.33 KB
/
MainActivity.java
File metadata and controls
38 lines (28 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.example.tabdemo;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost mhost = (TabHost) findViewById(android.R.id.tabhost); //Getting tab host by id.
TabSpec mspec = mhost.newTabSpec(getResources().getString(R.string.name1)); //Creating a tab
mspec.setIndicator(getResources().getString(R.string.indicator1),getResources().getDrawable(R.drawable.ic_launcher)).setContent(
new Intent(this, FirstActivity.class)); //Providing content to the tab
mhost.addTab(mspec); //adding tab to the tabhost
mspec = mhost.newTabSpec(getResources().getString(R.string.name2)); //Creating a tab
mspec.setIndicator(getResources().getString(R.string.indicator2),getResources().getDrawable(R.drawable.ic_launcher)).setContent(
new Intent(this, FirstActivity.class)); //Providing content to the tab
mhost.addTab(mspec); //adding tab to the tabhost
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}