Android TabHost 구성 요소 사용 방법 상세 설명
main.xml 레이아웃 파일:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
</TabHost>
inner.xml 파일:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</TabHost>
Main.java(주 Activity 클래스):
package com.android.test;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.provider.Contacts.Intents.UI;
import android.view.Window;
import android.widget.TabHost;
public class Main extends TabActivity implements TabHost.OnTabChangeListener {
private static final int TAB_INDEX_DIALER = 0;
private static final int TAB_INDEX_CALL_LOG = 1;
private static final int TAB_INDEX_CONTACTS = 2;
private static final int TAB_INDEX_FAVORITES = 3;
private TabHost mTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent intent = getIntent();
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
mTabHost = getTabHost();
mTabHost.setOnTabChangedListener(this);
// Setup the tabs
setupDialerTab();
setupCallLogTab();
setupContactsTab();
setupFavoritesTab();
setCurrentTab(intent);
}
public void onTabChanged(String tabId) {
Activity activity = getLocalActivityManager().getActivity(tabId);
if (activity != null) {
activity.onWindowFocusChanged(true);
}
}
private void setupCallLogTab() {
// Force the class since overriding tab entries doesn't work
Intent intent = new Intent("com.android.phone.action.RECENT_CALLS");
intent.setClass(this, Inner.class);
mTabHost.addTab(mTabHost.newTabSpec("call_log")
.setIndicator(" ",
getResources().getDrawable(R.drawable.ic_tab_unselected_recent))
.setContent(intent));
}
private void setupDialerTab() {
Intent intent = new Intent("com.android.phone.action.TOUCH_DIALER");
intent.setClass(this, Inner.class);
mTabHost.addTab(mTabHost.newTabSpec("dialer")
.setIndicator(" ",
getResources().getDrawable(R.drawable.ic_tab_unselected_dialer))
.setContent(intent));
}
private void setupContactsTab() {
Intent intent = new Intent(UI.LIST_DEFAULT);
intent.setClass(this, Main.class);
mTabHost.addTab(mTabHost.newTabSpec("contacts")
.setIndicator(" ",
getResources().getDrawable(R.drawable.ic_tab_unselected_contacts))
.setContent(intent));
}
private void setupFavoritesTab() {
Intent intent = new Intent(UI.LIST_STREQUENT_ACTION);
intent.setClass(this, Inner.class);
mTabHost.addTab(mTabHost.newTabSpec("favorites")
.setIndicator(" ",
getResources().getDrawable(R.drawable.ic_tab_unselected_starred))
.setContent(intent));
}
/**
* Sets the current tab based on the intent's request type
*
* @param intent Intent that contains information about which tab should be selected
*/
private void setCurrentTab(Intent intent) {
// Dismiss menu provided by any children activities
Activity activity = getLocalActivityManager().
getActivity(mTabHost.getCurrentTabTag());
if (activity != null) {
activity.closeOptionsMenu();
}
// Tell the children activities that they should ignore any possible saved
// state and instead reload their state from the parent's intent
intent.putExtra("", true);
// Choose the tab based on the inbound intent
String componentName = intent.getComponent().getClassName();
if (getClass().getName().equals(componentName)) {
if (false) {
//in a call, show the dialer tab(which allows going back to the call)
mTabHost.setCurrentTab(TAB_INDEX_DIALER);
} else if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
// launched from history (long-press home) --> nothing to change
} else if (true) {
// The dialer was explicitly requested
mTabHost.setCurrentTab(TAB_INDEX_DIALER);
}
}
}
}
Inner.java 클래스:
package com.android.test;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class Inner extends TabActivity implements TabHost.OnTabChangeListener {
private static final int TAB_INDEX_ALL = 0;
private static final int TAB_INDEX_MISSED = 1;
private static final int TAB_INDEX_OUTGOING = 2;
private static final int TAB_INDEX_RECEIVED = 3;
private TabHost mTabHost;
private TabWidget mTabWidget;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.inner);
mTabHost = getTabHost();
mTabHost.setOnTabChangedListener(this);
setupTabs();
mTabWidget = mTabHost.getTabWidget();
mTabWidget.setStripEnabled(false);
for (int i = 0; i < mTabWidget.getChildCount(); i++) {
TextView tv = (TextView) mTabWidget.getChildAt(i).findViewById(
android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(
android.R.color.white));
tv.setPadding(0, 0, 0,(int) tv.getTextSize());
tv.setText("Tab" + i);
mTabWidget.getChildAt(i).getLayoutParams().height =(int ) (3* tv.getTextSize());
mTabWidget.getChildAt(i).setBackgroundResource(R.drawable.tab_bg);
}
}
public void onTabChanged(String tabId) {
}
private void setupTabs() {
mTabHost.addTab(mTabHost.newTabSpec("all").setIndicator(
getString(R.string.inner)).setContent(
new Intent(this, Other.class)));
mTabHost.addTab(mTabHost.newTabSpec("Missed").setIndicator(
getString(R.string.inner)).setContent(
new Intent(this, Other.class)));
mTabHost.addTab(mTabHost.newTabSpec("Outgoing").setIndicator(
getString(R.string.inner)).setContent(
new Intent(this, Other.class)));
mTabHost.addTab(mTabHost.newTabSpec("Received").setIndicator(
getString(R.string.inner)).setContent(
new Intent(this, Other.class)));
}
}
효과 도 는 다음 과 같다.이상 이 바로 본문의 전체 내용 입 니 다.여러분 께 참고 가 될 수 있 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.