Reputation: 410
Basically I created an Activity with a CoordinatorLayout, everything seems to be working. But there is 2 AppBars. One is empty (no text) and is shown on top of the activity. While the other one behaves as it should on the coordinator layout: initially just text, no background; and as you slide up it move to the top of the screen, and it gains a background (if this sounds confusing just look at the animation here.
This are screenshots of how it looks:
I tried using:
requestWindowFeature(Window.FEATURE_NO_TITLE);
and
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
But neither seems to have any effect on the layout.
This is my Activities XML:
<?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="aris.projectaris.InfoPreviewActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_info_preview" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
Upvotes: 1
Views: 1112
Reputation: 15252
Looks like the default ActionBar
is still there even though you have added a Toolbar
. Make sure to set on of the following themes
android:theme="@style/Theme.AppCompat.NoActionBar"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
in the <application>
or appropriate <activity>
tag in your AndroidManifest.xml
.
EDIT:
If you use one of these themes, you must set up the Toolbar as the app bar in the onCreate
method of the Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar t = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(t);
}
Upvotes: 3