[UPDATE BELOW]
I'm trying to change the title in the default title bar after clicking an item in the RecyclerView which is inside onLoadFinished (AsyncTaskLoader) but title doesn't change. The idea is when I tab an item in the RecyclerView and data is loaded, title bar text should be changed too but it doesn't.
catsRecyclerView.addOnItemTouchListener(new RecyclerTouchListener(this, catsRecyclerView,new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
Categories category = categories.get(position);
int catId = category.getId();
setTitle(category.getTitle());
drawerLayout.closeDrawer(GravityCompat.START);
commonActions(); //restarting loader and executing other methods
}
@Override
public void onLongClick(View view, int position) {
}
}));
When I log category.getTitle() I get the correct text but title doesn't change how can I achieve that?
[Update]
Replaced the default title bar with a custom action bar here's the layout of the activity:
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include layout="@layout/actionbar"/>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
The actiobar layout
<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="40dp"
android:background="@color/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:id="@+id/primaryToolbar">
</android.support.v7.widget.Toolbar>
The activity
toolbar = findViewById(R.id.primaryToolbar);
setSupportActionBar(toolbar);
setTitle("My new title");
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
But it's size is so large taking the whole screen