private void initdata() { for (int i=0;i<titles.length;i++) { TextView textView = new TextView(this); textView.setText(titles[i]); textView.setTextSize(20); textView.setId(i+1000); textView.setOnClickListener(new Click()); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewPager.LayoutParams.WRAP_CONTENT, ViewPager.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(20,10,20,10); if(i==0) { textView.setTextColor(Color.RED); }else { textView.setTextColor(Color.BLACK); } arr.add(textView); lin.addView(textView,layoutParams);//布局ID } } class Click implements View.OnClickListener { @Override public void onClick(View view) { int id = view.getId(); pager.setCurrentItem(id-1000); } }
创建TextView
最新推荐文章于 2024-04-16 06:42:02 发布