简体   繁体   中英

How to show toast message when click tab?

I searched this question many time but I couldn't find a solution. I have a Tab Menu in my application. I want to show some text with toast when click another tab.

MainActivity.java; MainActivity.java

Page1Fragment.java; Fragment.java

What can I do about it? Thanks a lot.

In your MainActivity' onCreate method add this one at the bottom

    tabLayout.addOnTabSelectedListener(new OnTabSelectedListener() {
            @Override
            public void onTabSelected(Tab tab) {
                 Toast.makeText(MainActivity.this, "Tab clicked", 
   Toast.LENGTH_LONG).show();
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM