ActionBar is not displayed

I created a 3 tabbed project in android using TabHost

and TabSpec

. I am expanding my file Basic Action with TabActivity

Problem was ActionBar

not showing in the application. I used the theme Holo.Light.DarkActionBar

.

MainActivity.java

     public class MainActivity extends TabActivity {

    TabHost tabhost;

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


    tabhost=getTabHost();

    TabHost.TabSpec homespec=tabhost.newTabSpec("Home");
    homespec.setIndicator("Home",null);
    Intent homeintent=new Intent(this,HomeActivity.class);
    homespec.setContent(homeintent);

    TabHost.TabSpec eventspec=tabhost.newTabSpec("Event");
    eventspec.setIndicator("Event");
    Intent eventintent=new Intent(this,EventActivity.class);
    eventspec.setContent(eventintent);

    TabHost.TabSpec profilespec=tabhost.newTabSpec("Profile");
    profilespec.setIndicator("Profile");
    Intent profileintent=new Intent(this,ProfileActivity.class);
    profilespec.setContent(profileintent);

    tabhost.addTab(homespec);
    tabhost.addTab(eventspec);
    tabhost.addTab(profilespec);
    }
    }

      

activity_main.xml `

<TabHost
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@android:id/tabhost"
    android:layout_weight="1">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

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

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

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

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

      

Is there any other way to achieve this. Offer also?

+3


source to share


2 answers


Set a theme for this activity in AndroidManifest.xml:

<activity android:name=".MainActivity"
            android:theme="@android:style/Theme.Holo.Light"/>

      

Go to Activity_main and click in Design -> Theme (on the top bar, next to device name and landscape) -> Manifest Themes -> and select your theme.



edit: add this of course (unless you are intentionally forgotten)

<?xml version="1.0" encoding="utf-8"?>

      

+4


source


change your layout like this:



<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

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

</TabHost>

      

+2


source







All Articles