【问题标题】:How to show action bar in a tab group activity?如何在选项卡组活动中显示操作栏?
【发布时间】:2014-07-30 21:12:43
【问题描述】:

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

tab1的活动

public class EntriesTabActivity extends TabGroupActivity {

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

儿童活动

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>

【问题讨论】:

    标签: android android-actionbar


    【解决方案1】:

    我觉得您正在使用支持库进行开发,因为您想要 api8 的操作栏。您是否将 appcompat_v7 和 android-support-v4 正确包含到您的项目中?

    ActivityGroup 继承了 android.app.activity,我认为您不能将多个操作栏添加到子活动或片段,而只能添加到父活动。所以在我看来,不可能向子活动添加操作栏。除了 activityGroup 已被弃用我们应该改用 Fragment 和 FragmentManager API。

    【讨论】:

    • 是的。我已将 appcompat_v7 和 android-support-v4 库包含到我的项目中
    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多