diff --git a/demo/src/main/res/drawable-v21/selector_bg.xml b/demo/src/main/res/drawable-v21/selector_bg.xml
new file mode 100644
index 0000000..3a7b671
--- /dev/null
+++ b/demo/src/main/res/drawable-v21/selector_bg.xml
@@ -0,0 +1,5 @@
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/drawable/selector_bg.xml b/demo/src/main/res/drawable/selector_bg.xml
new file mode 100644
index 0000000..b8408d1
--- /dev/null
+++ b/demo/src/main/res/drawable/selector_bg.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/src/main/res/layout/activity_main.xml b/demo/src/main/res/layout/activity_main.xml
index b24230b..bbc03d3 100644
--- a/demo/src/main/res/layout/activity_main.xml
+++ b/demo/src/main/res/layout/activity_main.xml
@@ -35,6 +35,8 @@
app:textColorSelected="@color/tab_selected_color"
app:itemTextSize="8sp"
app:itemMarginTop="-5dp"
+ app:openTouchBg="true"
+ app:touchDrawable="@drawable/selector_bg"
/>
@@ -62,6 +66,8 @@
app:textColorSelected="@color/tab_selected_color"
app:itemTextSize="8sp"
app:itemMarginTop="-5dp"
+ app:openTouchBg="true"
+ app:touchDrawable="@drawable/selector_bg"
/>
diff --git a/demo/src/main/res/values/colors.xml b/demo/src/main/res/values/colors.xml
index 5784158..e354b4a 100644
--- a/demo/src/main/res/values/colors.xml
+++ b/demo/src/main/res/values/colors.xml
@@ -7,4 +7,5 @@
#F3F5F4
#515051
#D33D3C
+
diff --git a/library/src/main/java/com/chaychan/library/BottomBarItem.java b/library/src/main/java/com/chaychan/library/BottomBarItem.java
index f187eaa..19ec83b 100644
--- a/library/src/main/java/com/chaychan/library/BottomBarItem.java
+++ b/library/src/main/java/com/chaychan/library/BottomBarItem.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Gravity;
@@ -28,9 +29,14 @@ public class BottomBarItem extends LinearLayout {
private int mTextColorNormal = 0xFF999999; //描述文本的默认显示颜色
private int mTextColorSelected = 0xFF46C01B; //述文本的默认选中显示颜色
private int mMarginTop = 0;//文字和图标的距离,默认0dp
+ private boolean mOpenTouchBg = false;// 是否开启触摸背景,默认关闭
+ private Drawable mTouchDrawable;//触摸时的背景
+
private TextView mTextView;
private ImageView mImageView;
+
+
public BottomBarItem(Context context) {
this(context, null);
}
@@ -56,6 +62,10 @@ public BottomBarItem(Context context, @Nullable AttributeSet attrs, int defStyle
mTextColorSelected = ta.getColor(R.styleable.BottomBarItem_textColorSelected, mTextColorSelected);
mMarginTop = ta.getDimensionPixelSize(R.styleable.BottomBarItem_itemMarginTop, UIUtils.dip2Px(mContext, mMarginTop));
+
+ mOpenTouchBg = ta.getBoolean(R.styleable.BottomBarItem_openTouchBg, mOpenTouchBg);
+ mTouchDrawable = ta.getDrawable(R.styleable.BottomBarItem_touchDrawable);
+
ta.recycle();
checkValues();
@@ -73,6 +83,11 @@ private void checkValues() {
if (mIconSelectedResourceId == -1) {
throw new IllegalStateException("您还没有设置选中状态下的图标,请指定iconSelected的图标");
}
+
+ if (mOpenTouchBg && mTouchDrawable == null){
+ //如果有开启触摸背景效果但是没有传对应的drawable
+ throw new IllegalStateException("开启了触摸效果,但是没有指定touchDrawable");
+ }
}
private void init() {
@@ -92,6 +107,11 @@ private void init() {
layoutParams.topMargin = mMarginTop;
mTextView.setLayoutParams(layoutParams);
+ if (mOpenTouchBg){
+ //如果有开启触摸背景
+ setBackground(mTouchDrawable);
+ }
+
addView(view);
}
diff --git a/library/src/main/res/values/attr.xml b/library/src/main/res/values/attr.xml
index 01a8402..fe81aa2 100644
--- a/library/src/main/res/values/attr.xml
+++ b/library/src/main/res/values/attr.xml
@@ -15,5 +15,9 @@
+
+
+
+
\ No newline at end of file
diff --git a/library/src/main/res/values/colors.xml b/library/src/main/res/values/colors.xml
new file mode 100644
index 0000000..73bb0c1
--- /dev/null
+++ b/library/src/main/res/values/colors.xml
@@ -0,0 +1,5 @@
+
+
+ #ffffff
+ #DDDDDD
+
\ No newline at end of file