如何在标签组活动中显示操作栏?

时间:2014-07-30 07:47:49

标签: android android-actionbar

我有一个包含4个标签的标签组活动。 tab1中的tab1,tab2,tab3,tab4和两个子活动。如何在tab1的子activity2中显示操作栏。但是操作栏没有显示。我希望操作栏显示在一个子活动中。

tab1的活动

public class EntriesTabActivity extends TabGroupActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   startChildActivity("EntriesContentActivity", new Intent(this,EntriesContentActivity .class));
}   
}

ChildActivity

public class EntriesContentActivity extends ActionBarActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // construct the tab host
    setContentView(R.layout.entries_content);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.action_menu_entry, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_settings) {

        return true;
    }
    return super.onOptionsItemSelected(item);
}
}

我的清单文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iga.allergy"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
</uses-permission>

<!-- We must declare these two permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />

<application
    android:name="com.iga.allergy.AJ_Constant"
    android:allowBackup="true"
    android:icon="@drawable/app_icon"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name="com.iga.allergy.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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


    <activity
        android:name="com.iga.allergy.TabController"
        android:screenOrientation="portrait" />
    <activity
        android:name="com.iga.allergy.EntriesTabActivity"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustResize" />
  <activity
        android:name="com.iga.allergy.EntriesContentActivity"
        android:screenOrientation="portrait" />
    <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.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>

1 个答案:

答案 0 :(得分:0)

我觉得你正在使用支持库进行开发,因为你需要api8的actionbar。你是否正确地将appcompat_v7和android-support-v4包含在你的项目中?

ActivityGroup继承了android.app.activity,我认为你不能为子项或片段添加多个操作栏,只能添加到父活动。所以我认为不可能在子活动中添加操作栏。不推荐使用activityGroup我们应该使用Fragment和FragmentManager API。