Notification Bar ist Grau, das nach der Umsetzung Nav Schublade

Ich versuche zu lernen Implementierungen der Navigation Drawer in Android.

Einer Tätigkeit, die ich gemacht habe, die Navigation Schublade unter der Status Bar(transparent) und über die App-Leiste und alles funktioniert einwandfrei.(Screenshot Links)

In eine andere Tätigkeit in derselben App, die ich versuche zu erstellen Navigation Schublade, die zieht bis unter die App-Leiste. Aber hier, in der Statusleiste wird Grau aus irgendeinem Grund(ob nav Schublade ist offen oder geschlossen)(Screenshot Rechts). Andere als diese, alles scheint in Ordnung.

Unten ist der screenshot:

Notification Bar ist Grau, das nach der Umsetzung Nav Schublade

Das grüne Nav-Schublade ist ein fragment.

Was ich wissen will ist, wie man den Zustand normal(dunkler Schatten. Bitte denken Sie daran, wenn ich klicken Sie, dass zwei Pfeil-Symbol in der App-Leiste, es wird mich zu einer anderen Aktivität, die mit einem anderen Nav-Schublade, die funktioniert wie die im Material-Design(Volle Höhe des Bildschirms und kommt unter einem transparenten Status-Bar). Dies zeigt sich an der linken Seite der Abbildung.

Unten ist der code:

MainActivity.java:

public class MainActivity extends ActionBarActivity {
    Toolbar toolbar;
    DrawerLayout xDrawerLayout;

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

        toolbar = (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        xDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        xDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primary_dark));

        NavDrawerFragment mfragment = (NavDrawerFragment) getFragmentManager().findFragmentById(R.id.nav_drawer_fragment);
        mfragment.SetUp(xDrawerLayout, toolbar, R.id.nav_drawer_fragment);
    }
...

activity_alt.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include
        android:id="@+id/app_bar"
        layout="@layout/app_bar" />


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello_world" />

        </RelativeLayout>

        <fragment
            android:id="@+id/nav_drawer_fragment"
            android:name="com.rt.droid.mattest.NavDrawerFragment"
            android:layout_width="@dimen/nav_drawer_width"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            tools:layout="@layout/fragment_nav_drawer" />


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

</LinearLayout>

NavDrawerFragment.java:

public class NavDrawerFragment extends Fragment {

    private ActionBarDrawerToggle mDrawerToggle;
    private DrawerLayout mDrawerLayout;
    public DrawerLearner yDrawerLearner;

    public NavDrawerFragment() {
        //Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //Inflate the layout for this fragment
        View fView = inflater.inflate(R.layout.fragment_nav_drawer, container, false);
        //fView.setFitsSystemWindows(true);
        fView.setBackgroundColor(getResources().getColor(R.color.accent));
        return fView;
    }

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

    public void SetUp(DrawerLayout drawerLayout, Toolbar toolbar, int frag_id) {
        this.mDrawerLayout = drawerLayout;
        View drawerFrag = getActivity().findViewById(frag_id);
        mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getActivity().invalidateOptionsMenu();
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                getActivity().invalidateOptionsMenu();
            }
        };

        yDrawerLearner = new DrawerLearner(mDrawerLayout, drawerFrag, getActivity());
        yDrawerLearner.execute();

        this.mDrawerLayout.setDrawerListener(mDrawerToggle);
        mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.primary_dark));

        mDrawerLayout.post(new Runnable() {
            @Override
            public void run() {
                mDrawerToggle.syncState();
            }
        });

    }
}

fragment_nav_drawer.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.rt.droid.mattest.NavDrawerFragment">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/hello_blank_fragment" />

</FrameLayout>

app_bar.xml:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/primary"
    app:popupTheme="@style/AppTheme.PopupMenu"
    android:theme="@style/AppTheme.Toolbar">

</android.support.v7.widget.Toolbar>

styles.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppTheme.Base">
        <!-- Customize your theme here. -->
    </style>

    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>

    <style name="AppTheme.Toolbar" parent="ThemeOverlay.AppCompat.Dark">
        <item name="android:textColorPrimary">@color/primary_text</item>
        <item name="android:textColorSecondary">@color/accent</item>
    </style>

    <style name="AppTheme.PopupMenu" parent="ThemeOverlay.AppCompat.Dark">
        <item name="android:background">@color/accent</item>
    </style>

</resources>

styles.xml(v21):

<resources>
    <style name="AppTheme" parent="AppTheme.Base">
        <!-- Customize your theme here. -->
        <item name="android:colorPrimary">@color/primary</item>
        <item name="android:colorPrimaryDark">@color/primary_dark</item>
        <item name="android:colorAccent">@color/accent</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:statusBarColor">@android:color/transparent</item>
        <item name="android:windowTranslucentStatus">true</item>
    </style>

</resources>

Colors.xml(Abbildung zeigt Farbe, Muster):

Notification Bar ist Grau, das nach der Umsetzung Nav Schublade

Hinweis: ich möchte nicht zu gefährden, die Stile, etc. machen würde mein anderen Navigations-Schublade nicht funktioniert. In anderen Worten, ich bevorzuge eine Lösung, wobei beide Arten der navigation bar arbeitet, wie erwartet, in der gleichen app.

Bitte lassen Sie mich wissen, wenn Sie irgendeine info und ich werde es Bearbeiten, wenn erforderlich.
Edit: Hinzugefügt app_bar.xml & colors.xml für Klarheit.

  • entfernen Sie diese: DrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R. color.primary_dark));
  • entfernt, aber die status bar ist immer noch Grau.
  • dann ist das problem in der Symbolleiste
  • first off, können Sie mir bitte sagen, was ist das problem? Der Grund warum ich Frage ist, weil die gleichen Symbolleiste(app_bar) arbeitet in einer anderen Aktivität, in der gleichen Anwendung(siehe erste screenshot). Ich habe auch bearbeitet die Frage auf meine Symbolleiste layout.
InformationsquelleAutor rapidclock | 2015-05-17
Schreibe einen Kommentar