我是 Android 开发新手,我正在使用三个选项卡进行 TabHost
布局,因此我制作了 xml 文件:
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ntm">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/Present"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Simple"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView24"
android:layout_weight="1"/>
<TextView
android:text="Continuous"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView23"
android:layout_weight="1"/>
<TextView
android:text="Perfect Simple"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView15"
android:layout_weight="1"/>
<TextView
android:text="Perfect Continuous"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView8"
android:layout_weight="1"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" />
</TableLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/Past"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="NTM1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView25" />
</LinearLayout>
<LinearLayout
android:id="@+id/Future"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="NTM2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView26" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
这是我在相关 Activity 中初始化选项卡的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
}
TabHost tab =(TabHost) findViewById(R.id.ntm);
tab.setup();
TabHost.TabSpec spec1 = tab.newTabSpec("PRESENT");
spec1.setIndicator("PRESENT");
spec1.setContent(R.id.Present);
tab.addTab(spec1);
TabHost.TabSpec spec2 = tab.newTabSpec("PAST");
spec2.setIndicator("PAST");
spec2.setContent(R.id.Past);
tab.addTab(spec2);
TabHost.TabSpec spec3 = tab.newTabSpec("FUTURE");
spec3.setIndicator("FUTURE");
spec3.setContent(R.id.Future);
tab.addTab(spec3);
我收到此错误:
cannot resolve symbol
在每个方法上,例如 tab.setup()
或适用于 TabHost
和 TabSpec
对象的所有方法。
我尝试将代码复制/粘贴到主 Activity
中,没有出现任何错误,但应用程序立即崩溃
最佳答案
我发现了我的错误,我没有将初始化代码放入方法onCreate
我没有更多错误
关于java - 无法解析 TabHost 方法上的符号 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42422865/