Вопрос:

ViewPager - Changing the Up button Icon Depending on the Current Page

android android-viewpager

47 просмотра

1 ответ

923 Репутация автора

I'm attempting to change the up button icon depending on the current page in a ViewPager. For the first page I wish to display a cross icon and all subsequent pages to display the back arrow I have attempted the following in each fragment:

@override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
    actionBar.setHomeAsUpIndicator(R.drawable.ic_some_icon_goes_here);

    setHasOptionsMenu(true);
}

Unfortunately the icon does not change

Автор: TheKingOfAtlantis Источник Размещён: 22.08.2016 09:16

Ответы (1)


2 плюса

178 Репутация автора

Решение

You can use ViewPager.OnPageChangeListener and based on the position of the selected page in view pager you can change the appropriate icon. check the below link

https://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html

Let me know for any further help.

Автор: rahul Размещён: 22.08.2016 09:35
Вопросы из категории :
32x32