【发布时间】:2020-02-20 06:12:35
【问题描述】:
看起来像这样,我在这里使用未回答选项卡的适配器类,实际上我需要当我们选择单选按钮并单击下一步然后选项卡将被选为已回答 这是未选择的代码 1.从适配器类
public View getSelectedTabView(int position) {
View view = LayoutInflater.from(context).inflate(R.layout.custom_tab, null);
ImageView imageView = view.findViewById(R.id.custom_tab_circle);
TextView textView = view.findViewById(R.id.custom_tab_textView);
//textView.setText(mfragmentTitlelist.get(position+1));
//textView.setText(position);
//textView.setText((CharSequence) fragmentList.get(position));
StringBuilder builder = new StringBuilder();
builder.append(position+1).toString();
textView.setText(builder.toString());
imageView.setImageResource(R.drawable.selected_circle);
// here is image will be transparent
imageView.setAlpha(0.5f);
//.setTextColor(ContextCompat.getColor(context, R.color.yellow));
//ImageView tabImageView = view.findViewById(R.id.tabImageView);
//imageView.setImageResource(mFragmentIconList.get(position));
//imageView.setColorFilter(ContextCompat.getColor(context, R.color.background_color), PorterDuff.Mode.SRC_ATOP);
return view;
}
**2。现在我们在 Activity.java 中调用这段代码 **
highLightCurrentTab(position);
private void highLightCurrentTab(int position) {
TabLayout.Tab tab = tabLayout.getTabAt(position);
assert tab != null;
tab.setCustomView(null);
tab.setCustomView(adapter.getSelectedTabView(position));
/*tab.setCustomView(adapter.getPageTitle(position).charAt(position));*/
}
所以请帮助我在选择答案时该怎么做,我的标签图像将被选为已回答... 谢谢..
【问题讨论】:
标签: android android-fragments android-activity