user3746428 February 2016

Activity-based action bar/status bar visibility

I am trying to set up the action bars and the status bar within my app, however I have run into an issue. I did have it working, but it wasn't a clean way of doing things, so I decided to start over.

On the launch activity I want the status bar to be visible, with the pink background that I'm using throughout the app (no action bar). On the next view I want both the action bar and the status bar.

This is what I have within my launch activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="8dp"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="8dp"
    tools:context="com.andrewnwalker.mousetimes_california.ParkSelectActivity">

    <LinearLayout
        ...>

        <TextView
            .../>

        <TextView
            .../>

        <Button
            .../>

        <Button
            .../>
    </LinearLayout>
</android.support.design.widget.CoordinatorLayout>

And this is what I have in the second activity:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.andrewnwalker.mousetimes_california.MainActivity">

    <android.support.v7.widget.ActionBarContainer
        android:id="@+id/toolbar"
        android:layout        

Answers


Doug Stevenson February 2016

The status bar color conforming to material design is driven by the app's theme. You can read the official docs about this, as there's not enough information here to know for sure what's going on. You might be overriding the app theme on the first activity in the manifest or changing it somehow in the activity. The first activity does have a peculiar layout. There's no need to use CoordinatorLayout here if you don't have an action bar. If you just need to scroll the inner LinearLayout, just use a ScrollView instead.

To remove the action bar menu, make sure that you're not returning a menu in onCreateOptionsMenu or modifying anything in onPrepareOptionsMenu. Remove those methods if they're not needed.

Post Status

Asked in February 2016
Viewed 3,931 times
Voted 9
Answered 1 times

Search




Leave an answer