【发布时间】:2019-05-10 22:16:23
【问题描述】:
[以下更新]
单击 onLoadFinished (AsyncTaskLoader) 内的 RecyclerView 中的项目后,我试图更改默认标题栏中的标题,但标题没有改变。这个想法是当我在 RecyclerView 中选择一个项目并加载数据时,标题栏文本也应该更改,但它没有。
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) {
}
}));
当我记录 category.getTitle() 时,我得到了正确的文本,但标题没有改变我怎样才能做到这一点?
[更新]
将默认标题栏替换为自定义操作栏,这是活动的布局:
<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>
动作栏布局
<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>
活动
toolbar = findViewById(R.id.primaryToolbar);
setSupportActionBar(toolbar);
setTitle("My new title");
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
但它的尺寸太大了,占据了整个屏幕
【问题讨论】:
-
贴出整个代码,尤其是setTitle()
-
这是包含 setTitle 的函数,它在 onLoadFinished 里面
标签: android android-recyclerview listener asynctaskloader android-titlebar