From 8a5875837c3d1c31617812c6ee4476add2539150 Mon Sep 17 00:00:00 2001
From: chaychan <844738237@qq.com>
Date: Wed, 28 Jun 2017 10:36:29 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=A1=E7=9B=AE=E8=A7=A6?=
=?UTF-8?q?=E6=91=B8=E8=83=8C=E6=99=AF=E7=9A=84=E8=AE=BE=E7=BD=AE=EF=BC=8C?=
=?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=A2=9E=E5=8A=A0=E8=A7=A6=E6=91=B8=E8=83=8C?=
=?UTF-8?q?=E6=99=AF=E8=89=B2=E5=8F=98=E5=8C=96=E5=92=8C=E6=B0=B4=E6=B3=A2?=
=?UTF-8?q?=E7=BA=B9=E6=95=88=E6=9E=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/main/res/drawable-v21/selector_bg.xml | 5 +++++
demo/src/main/res/drawable/selector_bg.xml | 5 +++++
demo/src/main/res/layout/activity_main.xml | 8 ++++++++
demo/src/main/res/values/colors.xml | 1 +
.../com/chaychan/library/BottomBarItem.java | 20 +++++++++++++++++++
library/src/main/res/values/attr.xml | 4 ++++
library/src/main/res/values/colors.xml | 5 +++++
7 files changed, 48 insertions(+)
create mode 100644 demo/src/main/res/drawable-v21/selector_bg.xml
create mode 100644 demo/src/main/res/drawable/selector_bg.xml
create mode 100644 library/src/main/res/values/colors.xml
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