Как установить заголовок панели инструментов с помощью Retrofit android? - PullRequest
2 голосов
/ 03 июля 2019

Я использовал CollapsingToolbarLayout и пытаюсь динамически установить заголовок панели инструментов, используя модификацию, но она не работает. просто посмотрите на мой код: -

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);
                    }
                }

        }

Моя структура 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>

1 Ответ

0 голосов
/ 03 июля 2019

попробуйте это:

collapsingToolbarLayout.setTitleEnabled(false);
toolbar.setTitle("My Title");

при вызове setTitleEnabled(false); заголовок появляется на панели инструментов

...