【问题标题】:Android Studio, Tabs dont show when I run the projectAndroid Studio,当我运行项目时选项卡不显示
【发布时间】:2017-03-22 00:35:32
【问题描述】:

我有 Android Studio 2.2.2 和

我用一个 TabHost 和一个文本视图“hello world”创建了一个简单的项目,然后我用 USB 连接到我的手机运行项目,当应用程序运行时我看不到 TabHost, 我只能看到“hello world”Textview....标签缺少

项目很简单,只是为了说明问题。

*在res/layout/activity_main.xml项目中可以很好的看到TabHost

提前致谢

例子:

MainActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

activity_main.xml(相对布局)

Layout Preview

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:id="@+id/textView" />

<TabHost
    android:layout_width="200dip"
    android:layout_height="300dip"
    android:layout_below="@+id/textView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">

    <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" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:id="@+id/tab1"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/tab3"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>
        </FrameLayout>
    </LinearLayout>
</TabHost>

【问题讨论】:

  • 发布主要活动,你在写这篇文章时参考的是什么指南?

标签: android android-studio tabs android-tabhost


【解决方案1】:

主活动

    th= (TabHost) findViewById(R.id.th);
    th.setup();

    TabHost.TabSpec tab1=th.newTabSpec("Tab1");
    tab1.setIndicator("Page");
    tab1.setContent(R.id.tab1);
    th.addTab(tab1);

=/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-09
    • 2019-06-16
    • 2021-11-23
    • 2019-02-15
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多