只需尝试更改Android应用程序选项卡上的文本。谁知道会有这么多麻烦。如何解决“无法解决”的问题mTabHost,tabs_bg和tabsText的“无法解析或不是字段”错误
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Tabs extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabs);
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
setupTab(new TextView(this), "List");
setupTab(new TextView(this), "Map");
}
private void setupTab(final View view, final String tag) {
View tabview = createTabViewe(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.tabs, menu);
return true;
}
}
答案 0 :(得分:0)
您需要声明mTabHost
TabHost mTabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
tabs_bg
是一种布局。你的布局文件夹中有tabs_bg.xml
吗?您还需要检查tabs_bg.xml
tabsText
的textview