-3
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TableLayout;
import android.widget.TabHost;
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
TabLayout tabLayout;
ViewPager viewPager;
ViewPagerAdapter viewpagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar=(Toolbar)findViewById(R.id.toolBar);
setSupportActionBar(toolbar);
tabLayout=(TabLayout)findViewById(R.id.tabLayout);
viewPager=(ViewPager)findViewById(R.id.viewpager);
viewpagerAdapter=new ViewPagerAdapter(getSupportFragmentManager());
viewpagerAdapter.addFragments(new HomeFragment(),"Home");
viewpagerAdapter.addFragments(new TopFreeFragment(),"TopFree");
viewpagerAdapter.addFragments(new TopPaidFragment(),"TopPaid");
viewPager.setAdapter(viewpagerAdapter);
tabLayout.setupWithViewPager(viewPager);
Home.setIndicator("",getResources().getDrawable(R.drawable.iconimage1_design));
TopFree.setIndicator("",getResources().getDrawable(R.drawable.iconimage2_design));
TopPaid.setIndicator("",getResources().getDrawable(R.drawable.iconimage3_design));
}
}
在最後3條語句中,紅色的Home,TopFree,TopPaid,shom標誌着我應該提供哪些文本而不是這三個名稱。 任何建議表示讚賞。如何在標籤主機中添加圖標而不是文本