Java 如何使用改型android设置工具栏标题?

Java 如何使用改型android设置工具栏标题?,java,android,retrofit2,toolbar,Java,Android,Retrofit2,Toolbar,我使用了CollasingToolbarLayout,并尝试使用改型动态设置工具栏标题,但它不起作用。请看我的代码:- Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ApiInterface api = ApiClient.getApiService(); Call<GetAttributesResponse> call = api.getA

我使用了CollasingToolbarLayout,并尝试使用改型动态设置工具栏标题,但它不起作用。请看我的代码:-

Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final ApiInterface api = ApiClient.getApiService();
    Call<GetAttributesResponse> call = api.getAttributes(27, attributId);

    call.enqueue(new Callback<GetAttributesResponse>() {
        @SuppressLint("SetTextI18n")
        @Override
        public void onResponse(@NonNull Call<GetAttributesResponse> call, @NonNull Response<GetAttributesResponse> response) {
            if (response.code() == 200) {
                if (response.body() != null) {
                        titleName = response.body().getData().getAttributeName();
                        getSupportActionBar().setTitle(titleName);
                        toolbar.setTitle(titleName);
                    }
                }

        }
Toolbar-Toolbar=findviewbyd(R.id.Toolbar);
设置支持操作栏(工具栏);
最终ApiInterface api=ApiClient.getApiService();
Call Call=api.getAttributes(27,attributeID);
call.enqueue(新回调(){
@SuppressLint(“SetTextI18n”)
@凌驾
public void onResponse(@NonNull调用,@NonNull响应){
if(response.code()==200){
if(response.body()!=null){
titleName=response.body().getData().getAttributeName();
getSupportActionBar().setTitle(标题名);
toolbar.setTitle(titleName);
}
}
}
我的Xml代码结构:-

<android.support.design.widget.CoordinatorLayout 
<android.support.design.widget.AppBarLayout
    <android.support.design.widget.CollapsingToolbarLayout

         <ImageView
         </ImageView>
         <android.support.v7.widget.Toolbar
         </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

试试这个:

折叠ToolbarLayout.setTitleEnabled(false);
工具栏。设置标题(“我的标题”);

调用
setTitleEnabled(false);
时,标题会出现在工具栏中

是否检查API响应是否成功?请尝试调试并检查
getSupportActionBar().setTitle(titleName)
这正在工作。显示包含工具栏的xml文件。并使用您在自定义工具栏中添加的文本视图,而不是使用
工具栏title@MilanJoseph我已经检查了getSupportActionBar().setTitle(标题名);不工作,API响应正在工作。@ρц∑ρєK我添加了我的XML表单集。请查看我的问题,如果可能,给我答复谢谢。@HitechP:在
工具栏中添加标题文本视图。
。请参阅