我已经决定我的选项卡界面使用视图..。我遵循选项卡界面教程,本教程的结果是在我的选项卡下有4个没有内容(文本)的选项卡。
我想知道视图是如何工作的。如何使方法将内容设置为来自另一个类的选项卡。因此,main.java是我的主文件,包含视图(选项卡)。maps有谷歌地图导航代码。
如何调用方法setupTab并将导航函数设置为选项卡1。
在这里你可以看到我的代码:
提前感谢!
package CustomTabs;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
public class CustomTabs extends Activity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
setContentView(R.layout.main);
setupTabHost();
setupTab(new TextView(this), "Tab 1", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 2", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 3", getResources().getDrawable(R.drawable.ic_tab_artists));
setupTab(new TextView(this), "Tab 4", getResources().getDrawable(R.drawable.ic_tab_artists));
{
final View v = mTabHost.getTabWidget().getChildAt(0);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(1);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(2);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
{
final View v = mTabHost.getTabWidget().getChildAt(3);
v.setBackgroundDrawable(getResources().getDrawable(R.drawable.tab_bg_selector));
TextView tv = (TextView) v.findViewById(android.R.id.title);
tv.setTextColor(this.getResources().getColorStateList(R.drawable.tab_text_selector));
}
}
private void setupTab(final View view, final String tag, Drawable icon) {
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tag, icon).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
}发布于 2011-01-12 16:19:44
您需要创建一些活动才能做到这一点。我的样本采取了2个活动,第一个活动将扩展TabActivity,第二个活动将扩展活动。
以下是我的简单示例:
扩展的
package com.bsoft.activity;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import com.bsoft.shared.Shared;
public class ViewActivity extends TabActivity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
String[] strVal = this.getIntent().getExtras().getString("content").split(Shared.SPACE);
setTitle(strVal[1]);
Intent paliIntent = new Intent(this, PaliActivity.class);
paliIntent.putExtra("val", strVal[2]);
Intent indonesiaIntent = new Intent(this, IndonesiaActivity.class);
indonesiaIntent.putExtra("val", strVal[3]);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("one").setIndicator("Pali").setContent(paliIntent));
tabHost.addTab(tabHost.newTabSpec("two").setIndicator("Indonesia").setContent(indonesiaIntent));
}
} package com.bsoft.activity;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import com.bsoft.shared.Shared;
public class IndonesiaActivity extends Activity {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.indonesia);
String val = this.getIntent().getExtras().getString("val");
WebView indonesiaContent = (WebView) findViewById(R.id.wvIndoContent);
indonesiaContent.loadData("" + val.replace("\n", "
") + "", Shared.MIME_TYPE, Shared.ENCODING);
Shared s = new Shared();
s.SetZoomControls(indonesiaContent, this);
}
}https://stackoverflow.com/questions/4670553
复制相似问题