... 私はタブインターフェイスチュートリアルに従うと、このチュートリアルの結果は私のタブの下にコンテンツのない4つのタブ(テキスト)..ですアンドロイド:私は私のタブインターフェイスのためのビューを使用することを決定したCustomTabs
私は私は別のクラスからタブにコンテンツを設定するメソッドを作ることができます.. main.javaはビュー(タブ)を持つ私のメインファイルです。 Tab1.javaにはGoogleマップのナビゲーションコードがあります。事前に
ありがとう:私はあなたが私のコードを見ることができる方法の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);
}
}
いいえ私はそうは思わない..私は言ったことができるビューメソッドを作成することを望んでいた..例public void()setcontent View v {TextView textview = new TextView(this); textview.setText( "test")}しかし、私はこのメソッドを作成する方法を知らない。 – anddevelop
申し訳ありませんが、あなたの質問は本当にありません。あなたは、タブのコンテンツを設定する方法を尋ねました。特定のクラスを実行するインテントを作成します。インテントintent = new Intent()。setClass(this、your_class.class); your_classでは、setTextまたは何をしたいのかを定義できます。 – springrolls