Skip to content

Commit

Permalink
增加重复点击过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaolei9527 committed Mar 27, 2018
1 parent 41f1266 commit 0bcad71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions bottomtabbar/src/main/java/sakura/bottomtabbar/BottomTabBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
* Created by 赵磊 on 2017/8/11.
*/

public class BottomTabBar extends LinearLayout implements ViewPager.OnPageChangeListener, View.OnClickListener {
public class BottomTabBar extends LinearLayout implements ViewPager.OnPageChangeListener, View.OnClickListener {

private Context context;
private LinearLayout mLayout;
Expand Down Expand Up @@ -68,7 +70,7 @@ public class BottomTabBar extends LinearLayout implements ViewPager.OnPageChang
private LinearLayout.LayoutParams tab_item_imgparams;
private LayoutParams tab_item_tvparams;
private int mReplaceLayout = 0;
private OnTabChangeListener listener=null;
private OnTabChangeListener listener = null;

//mViewpager界面滑动
@Override
Expand Down Expand Up @@ -108,9 +110,17 @@ public void onPageScrollStateChanged(int state) {

}

View last = null;

//Tab点击事件处理
@Override
public void onClick(View v) {
if (last == v) {
Log.e("BottomTabBar", "重复点击");
return;
} else {
last = v;
}
for (int i = 0; i < tabIdList.size(); i++) {
if (tabIdList.get(i).equals(v.getTag())) {
if (mViewpager != null) {
Expand All @@ -126,7 +136,7 @@ public void onClick(View v) {
changeTab(i);
}
//绑定点击监听回调
if (listener!=null){
if (listener != null) {
listener.onTabChange(i, v);
}
}
Expand Down Expand Up @@ -338,6 +348,7 @@ public BottomTabBar addTabItem(final String name, Drawable drawable) {
tab_item_tv.setTextSize(fontSize);
tab_item_tv.setText(name);
if (tabIdList.size() == 1) {
last = TabItem;
tab_item_tv.setTextColor(selectColor);
} else {
tab_item_tv.setTextColor(unSelectColor);
Expand Down Expand Up @@ -379,6 +390,7 @@ public BottomTabBar addTabItem(final String name, Drawable selectdrawable, Drawa
tab_item_tv.setTextSize(fontSize);
tab_item_tv.setText(name);
if (tabIdList.size() == 1) {
last = TabItem;
tab_item_tv.setTextColor(selectColor);
tab_item_img.setBackground(selectdrawable);
} else {
Expand Down Expand Up @@ -430,6 +442,7 @@ public BottomTabBar addTabItem(final String name, Drawable drawable, Class fragm
tab_item_tv.setTextSize(fontSize);
tab_item_tv.setText(name);
if (tabIdList.size() == 1) {
last = TabItem;
tab_item_tv.setTextColor(selectColor);
} else {
tab_item_tv.setTextColor(unSelectColor);
Expand Down Expand Up @@ -480,6 +493,7 @@ public BottomTabBar addTabItem(final String name, Drawable selectdrawable, Drawa
tab_item_tv.setTextSize(fontSize);
tab_item_tv.setText(name);
if (tabIdList.size() == 1) {
last = TabItem;
tab_item_tv.setTextColor(selectColor);
tab_item_img.setBackground(selectdrawable);
} else {
Expand Down

0 comments on commit 0bcad71

Please sign in to comment.