Add Icons to SlidingTabLayout instead of Text

后端 未结 11 2020
执笔经年
执笔经年 2020-12-02 23:57

I\'m implementing a SlidingTabLayout in my android application. What my query is that I\'d like to implement icons in my Sliding Tabs instead of texts for navigation. I sear

11条回答
  •  长情又很酷
    2020-12-03 00:33

    Ok.. there are many ways of implementing this change. This is the most quick and dirty one, just for the idea..

    Substitue the method SlidingTabLayout.populateTabStrip() for this..

        private void populateTabStrip() {
        final OnClickListener tabClickListener = new TabClickListener();
    
        View tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_notif_icon_only, mTabStrip, false);
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    
        tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_weather_icon_only, mTabStrip, false);
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    
        tabView = LayoutInflater.from(getContext()).inflate(R.layout.tab_calendar_icon_only, mTabStrip, false);
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    

    Create each layout this way LinearLayout > ImageView elements, src pointing to icon..

提交回复
热议问题