Can't find Toolbar in an included layout
You are overriding the id of toolbar in the include tag. So the R.id.toolbar
is no longer id of your included toolbar for your activity but now it is R.id.app_bar
instead.
If you keep the id in include tag then use following code to access your toolbar:
Toolbar toolbar = (Toolbar) activity.findViewById(R.id.app_bar);
Android toolbar menu is not showing
I'm not sure why, but when i place everything related menu inflating in onPrepareOptionsMenu method, everything works fine.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.dashboard, menu);
return super.onCreateOptionsMenu(menu);
}
can't find textView id inside toolbar
You are giving two different id to toolbar layout
android:id="@+id/my_toolbar"
and in main layout while including you are giving
<include
layout="@layout/custom_toolbar"
android:id="@+id/toolbar" />
make these ids same
Missing toolbar in Android Studio?
The toolbar that is missing is associated with a constraint based layout, and it missing because the layout for your new view does not have a constraint based layout.
You can right click the view and click Convert to ConstraintBasedLayout
in the dropdown menu to restore that bar.
AppBarLayout is not on the top of the screen
In res/values/styles
set your style to NoActionBar
theme, like:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Now, you should lose your regular ActionBar and you can work with your toolbar.
EDIT: What OP tried to acomplish was position included layout below AppBar
layout in CoordinatorLayout
. That's accomplished by adding app:layout_behavior="@string/appbar_scrolling_view_behavior"
to include layout.
collapsing toolbar layout won't collapse
Please try this. It will work.
<?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:background="@color/colorWhite"
tools:context=".Controllers.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/AppBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:textAlignment="center"
app:contentScrim="@color/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:title="Hero Title">
<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:background="#000000"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v7.widget.RecyclerView
android:id="@+id/herosRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
Related Topics
Eclipse Installation Error: Install_Failed_Uid_Changed
How to Get a Non Scrollable Listview
How to Modify Ripple Color When Using Attr/Selectableitembackground as Background
Android Device Does Not Show Up in Adb List
How to Use the Proguard in Android Studio
How to Use Data-Binding with Fragment
Android Splash Screen Sizes for Ldpi,Mdpi, Hdpi, Xhdpi Displays? - Eg:1024X768 Pixels for Ldpi
Evenly Spacing Views Using Constraintlayout
" App-Release.Apk" How to Change This Default Generated APK Name
Android/Firebase - Error While Parsing Timestamp in Gcm Event - Null Timestamp
How to Make a Edittext Box in a Dialog
How to Analyze Memory Using Android Studio
Receiver Not Registered Exception Error
How to Use Fragments in Android