ActionBar не се вижда при използване на раздели

Телефон: Samsung Galaxy S1
Android: 2.3.3
android-support-library: v18
minSdkVersion: 7

Когато добавяте раздели към ActionBar с помощта на библиотеката за поддръжка (appcompat), ActionBar изчезва -> фрагментът заема празното екранно пространство. Ако не добавя раздели към ActionBar, всичко е наред (ActionBar се вижда). Какво трябва да се направи, за да виждате винаги ActionBar.

package test.appcompat;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBar.Tab;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


public class Main extends ActionBarActivity implements ActionBar.TabListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        final ActionBar ab = getSupportActionBar();
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        ab.addTab(ab.newTab().setText("tab 1").setTabListener(this), 0);
        ab.addTab(ab.newTab().setText("tab 2").setTabListener(this), 1);
    }

    @Override
    public void onTabReselected(Tab arg0, FragmentTransaction arg1) { }
    @Override
    public void onTabUnselected(Tab arg0, FragmentTransaction arg1) { }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        Fragment f = new MyFragment();

        Bundle args = new Bundle();
        args.putString(MyFragment.ARG_TEXT, "Tab: "+ tab.getPosition());
        f.setArguments(args);

        getSupportFragmentManager().beginTransaction()
            .replace(android.R.id.content, f)
            .commit();
    }
}

class MyFragment extends Fragment {
    public static final String ARG_TEXT = "---";

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment, container, false);
        ((TextView) v.findViewById(R.id.text))
            .setText(getArguments().getString(ARG_TEXT) + " hello");

        return v;
    }
}


Манифест (добавен DarkActionBar към дейността):

    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="test.appcompat.Main"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>


styles.xml:

<resources>
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat"> <!-- android:Theme.Light -->
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>


fragment.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#BAF8EC" >

    <TextView android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="32sp"
    android:textColor="#AAE720"
    android:text="Hello World"
    />

</RelativeLayout>

person Paradiesstaub    schedule 14.10.2013    source източник


Отговори (1)


Актуализирането до android-support-library v19 реши проблема.

person Paradiesstaub    schedule 06.11.2013