簡體   English   中英

Android ActionBar 未顯示

[英]Android ActionBar not showing

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

appbar 仍然沒有顯示,我們可以在這里看到: 沒有操作欄

但是,我假設工具欄存在於程序中,因為我在程序曾經崩潰的地方沒有收到任何 NullPointException。 所以我認為更多的是樣式表問題。

這是活動 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));
}

那么,有誰知道為什么操作欄甚至沒有出現?

額外信息:顯示的片段是一個 libGDX 片段。

Theme.AppCompat.Light.NoActionBar

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

也許您應該更改“無操作欄”

您將工具欄隱藏在框架布局下。將您的布局更改為

<android.support.v4.widget.DrawerLayout..>
  <LinearLayout 
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:orientation="vertical">
      <android.support.v7.widget.Toolbar..>
      <FrameLayout ../>
  </LinearLayout>
  <!-- navigation Fragment -->
  <fragment ../>
</android.support.v4.widget.DrawerLayout> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM