Created
December 9, 2015 23:26
-
-
Save Taishi-Y/38e9dbb2245598ed28ea to your computer and use it in GitHub Desktop.
AppCompatActivityでスクリーン下部にTabを表示する方法 ref: http://qiita.com/Taishi-Y/items/f83cb42e834df16e348c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" > | |
<TabHost | |
android:id="@+id/tabHost" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" > | |
<LinearLayout | |
android:id="@+id/linearLayout1" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:orientation="vertical" > | |
<FrameLayout | |
android:id="@android:id/tabcontent" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:layout_weight="1" > | |
<LinearLayout | |
android:id="@+id/tab1" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#ffc916" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:text="search activity" /> | |
</LinearLayout> | |
<LinearLayout | |
android:id="@+id/tab2" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#da8200" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:text="picture activity" /> | |
</LinearLayout> | |
<LinearLayout | |
android:id="@+id/tab3" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:background="#5b89ff" | |
android:orientation="vertical"> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:text="My page" /> | |
</LinearLayout> | |
</FrameLayout> | |
<TabWidget | |
android:id="@android:id/tabs" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" > | |
</TabWidget> | |
</LinearLayout> | |
</TabHost> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TabHostActivity extends AppCompatActivity { | |
TabHost tabHost; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.tab_host_activity); | |
TabHost host = (TabHost) findViewById(R.id.tabHost); | |
host.setup(); | |
//Tab 1 | |
TabHost.TabSpec spec = host.newTabSpec("Tab One"); | |
spec.setContent(R.id.tab1); | |
spec.setIndicator("Search"); | |
host.addTab(spec); | |
//Tab 2 | |
spec = host.newTabSpec("Tab Two"); | |
spec.setContent(R.id.tab2); | |
spec.setIndicator("Photo"); | |
host.addTab(spec); | |
//Tab 3 | |
spec = host.newTabSpec("Tab Three"); | |
spec.setContent(R.id.tab3); | |
spec.setIndicator("MYPage"); | |
host.addTab(spec); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment