|
@@ -23,8 +23,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|
|
/**
|
|
|
* Created by xianguangjin on 16/5/20.
|
|
|
*/
|
|
|
-public class YTabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
- private ArrayList<YTab> tabs = new ArrayList<>();
|
|
|
+public class TabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
+ private ArrayList<Tab> tabs = new ArrayList<>();
|
|
|
|
|
|
private int curTab = 0;
|
|
|
private int preTab = 0;
|
|
@@ -32,17 +32,17 @@ public class YTabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
private MainMenuAdapter adapter;
|
|
|
private GridLayoutManager layoutManager;
|
|
|
|
|
|
- public YTabLayout(Context context) {
|
|
|
+ public TabLayout(Context context) {
|
|
|
super(context);
|
|
|
init(context, null, 0);
|
|
|
}
|
|
|
|
|
|
- public YTabLayout(Context context, AttributeSet attrs) {
|
|
|
+ public TabLayout(Context context, AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
init(context, attrs, 0);
|
|
|
}
|
|
|
|
|
|
- public YTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
+ public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
init(context, attrs, defStyleAttr);
|
|
|
}
|
|
@@ -50,22 +50,22 @@ public class YTabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
setHasFixedSize(true);
|
|
|
TypedArray array = context.obtainStyledAttributes(attrs,
|
|
|
- R.styleable.YTabLayout, defStyleAttr, 0);
|
|
|
+ R.styleable.TabLayout, defStyleAttr, 0);
|
|
|
|
|
|
// tabBuilder
|
|
|
int normalTextSize = array.getDimensionPixelSize(
|
|
|
- R.styleable.YTabLayout_android_textSize,
|
|
|
+ R.styleable.TabLayout_android_textSize,
|
|
|
getResources().getDimensionPixelSize(R.dimen.qmui_tab_segment_text_size));
|
|
|
|
|
|
normalTextSize = array.getDimensionPixelSize(
|
|
|
- R.styleable.YTabLayout_normal_text_size, normalTextSize);
|
|
|
+ R.styleable.TabLayout_normal_text_size, normalTextSize);
|
|
|
int selectedTextSize = normalTextSize;
|
|
|
selectedTextSize = array.getDimensionPixelSize(
|
|
|
- R.styleable.YTabLayout_selected_text_size, selectedTextSize);
|
|
|
+ R.styleable.TabLayout_selected_text_size, selectedTextSize);
|
|
|
|
|
|
mTabBuilder = new MenuTabBuilder(context)
|
|
|
.setTextSize(normalTextSize, selectedTextSize)
|
|
|
- .setIconPosition(array.getInt(R.styleable.YTabLayout_icon_position,
|
|
|
+ .setIconPosition(array.getInt(R.styleable.TabLayout_icon_position,
|
|
|
QMUITab.ICON_POSITION_LEFT));
|
|
|
|
|
|
array.recycle();
|
|
@@ -86,7 +86,7 @@ public class YTabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
adapter.setList(tabs);
|
|
|
}
|
|
|
|
|
|
- public YTabLayout addTab(YTab tab) {
|
|
|
+ public TabLayout addTab(Tab tab) {
|
|
|
tabs.add(tab);
|
|
|
return this;
|
|
|
}
|
|
@@ -112,19 +112,19 @@ public class YTabLayout extends RecyclerView implements OnItemClickListener {
|
|
|
|
|
|
Fragment fragment;
|
|
|
for (int i = 0; i < tabs.size(); i++) {
|
|
|
- YTab yTab = tabs.get(i);
|
|
|
+ Tab tab = tabs.get(i);
|
|
|
fragment = manager.findFragmentByTag("tab_" + i);
|
|
|
|
|
|
if (tabIndex == i) {
|
|
|
- yTab.setSelected(true);
|
|
|
+ tab.setSelected(true);
|
|
|
if (fragment == null) {
|
|
|
- fragment = yTab.fragment;
|
|
|
+ fragment = tab.fragment;
|
|
|
transaction.add(R.id.container, fragment, "tab_" + tabIndex);
|
|
|
} else {
|
|
|
transaction.show(fragment);
|
|
|
}
|
|
|
} else {
|
|
|
- yTab.setSelected(false);
|
|
|
+ tab.setSelected(false);
|
|
|
if (fragment == null) {
|
|
|
continue;
|
|
|
}
|