Android ActionBar 不显示

标签 android android-layout android-fragments android-actionbar

按照此处的说明操作后: http://developer.android.com/training/appbar/setting-up.html

应用栏仍然没有显示,正如我们在这里看到的: No Action Bar

但是,我假设程序中存在工具栏,因为我没有在程序曾经崩溃的地方得到任何 NullPointException。所以我认为更多的是样式表问题。

这是 Activity XML

<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="pt.bluecover.wearable3d.DrawerActivity">

    <!-- placed here as explained @
    http://developer.android.com/training/appbar/setting-up.html -->
    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:elevation="4dp"
        android:theme="@style/AppBar"
        app:popupTheme="@style/Popup"/>

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment
        android:id="@+id/navigation_drawer"
        android:name="pt.bluecover.wearable3d.NavigationDrawerFragment"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        tools:layout="@layout/drawer_drawer" />

</android.support.v4.widget.DrawerLayout>

这是 styles.xml

<resources>
    <style name="AppBar" parent="ThemeOverlay.AppCompat.ActionBar"/>
    <style name="Popup" parent="ThemeOverlay.AppCompat.Light" />
    <style name="GdxTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

</resources>

我正在初始化它,在 AppCompatActivity 的类上:

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

    //lets set the toolbar
    Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);

    mNavigationDrawerFragment = (NavigationDrawerFragment)
            getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(
            R.id.navigation_drawer,
            (DrawerLayout) findViewById(R.id.drawer_layout));
}

那么,有人知道为什么操作栏甚至不显示吗?

额外信息:显示的 fragment 是一个 libGDX fragment 。

最佳答案

“Theme.AppCompat.Light.NoActionBar

<style name="GdxTheme" parent="Theme.AppCompat.Light.NoActionBar">

也许您应该更改“无操作栏”

关于Android ActionBar 不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36481770/

相关文章:

java - Android 中的首选项不会保留

android - 以编程方式添加多个 fragment

android - 将 View 元素放在 TableLayout 的第一列

android - 如何使用新的设计库 API 正确隐藏和显示操作栏?

android - 如何从一个 Activity 返回到一个 Fragment?

安卓 : References to a Context and memory leaks

android - 如何修复在 OnCreateView() 中变为 null 的 List<>

java - 是否有原因导致线程仅在我强制调试时才执行?

java - 使用 BottomBar 可以防止 fragment 打开?

java - 按下后退按钮时如何获取最后使用的 Fragment