提交 8a587583 编写于 作者: C chaychan

增加条目触摸背景的设置,可以增加触摸背景色变化和水波纹效果

上级 c136a18d
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/selector_grey">
<item android:drawable="@color/tab_gb"/>
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/selector_grey" android:state_pressed="true"/>
<item android:drawable="@color/tab_gb"/>
</selector>
\ No newline at end of file
......@@ -35,6 +35,8 @@
app:textColorSelected="@color/tab_selected_color"
app:itemTextSize="8sp"
app:itemMarginTop="-5dp"
app:openTouchBg="true"
app:touchDrawable="@drawable/selector_bg"
/>
<com.chaychan.library.BottomBarItem
......@@ -48,6 +50,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"
/>
<com.chaychan.library.BottomBarItem
......@@ -75,6 +81,8 @@
app:textColorSelected="@color/tab_selected_color"
app:itemTextSize="8sp"
app:itemMarginTop="-5dp"
app:openTouchBg="true"
app:touchDrawable="@drawable/selector_bg"
/>
</com.chaychan.library.BottomBarLayout>
......
......@@ -7,4 +7,5 @@
<color name="tab_gb">#F3F5F4</color>
<color name="tab_normal_color">#515051</color>
<color name="tab_selected_color">#D33D3C</color>
</resources>
......@@ -2,6 +2,7 @@ package com.chaychan.library;
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 class BottomBarItem extends LinearLayout {
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 @@ public class BottomBarItem extends LinearLayout {
if (mIconSelectedResourceId == -1) {
throw new IllegalStateException("您还没有设置选中状态下的图标,请指定iconSelected的图标");
}
if (mOpenTouchBg && mTouchDrawable == null){
//如果有开启触摸背景效果但是没有传对应的drawable
throw new IllegalStateException("开启了触摸效果,但是没有指定touchDrawable");
}
}
private void init() {
......@@ -92,6 +107,11 @@ public class BottomBarItem extends LinearLayout {
layoutParams.topMargin = mMarginTop;
mTextView.setLayoutParams(layoutParams);
if (mOpenTouchBg){
//如果有开启触摸背景
setBackground(mTouchDrawable);
}
addView(view);
}
......
......@@ -15,5 +15,9 @@
<attr name="textColorSelected" format="color"/>
<!--文字和图标的顶部距离-->
<attr name="itemMarginTop" format="dimension"/>
<!--是否开启触摸背景效果-->
<attr name="openTouchBg" format="boolean"/>
<!--设置触摸背景-->
<attr name="touchDrawable" format="reference"/>
</declare-styleable>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
<color name="selector_grey">#DDDDDD</color>
</resources>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册