Skip to content

Commit 50cdc23

Browse files
committed
add ripple effect
1 parent cd6916c commit 50cdc23

File tree

9 files changed

+46
-25
lines changed

9 files changed

+46
-25
lines changed

app/src/main/java/com/brian/common/view/TitleBar.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.view.LayoutInflater;
77
import android.view.View;
88
import android.view.ViewGroup;
9+
import android.widget.ImageView;
910
import android.widget.LinearLayout;
1011
import android.widget.TextView;
1112

@@ -22,8 +23,8 @@ public class TitleBar extends LinearLayout {
2223
/**
2324
* UI元素
2425
*/
25-
private TextView mLeftText;
26-
private TextView mRightText;
26+
private ImageView mLeftBtn;
27+
private ImageView mRightBtn;
2728
private TextView mTitleText;
2829

2930
public TitleBar(Context context, AttributeSet attrs, int defStyle) {
@@ -32,20 +33,18 @@ public TitleBar(Context context, AttributeSet attrs, int defStyle) {
3233
}
3334

3435
public TitleBar(Context context, AttributeSet attrs) {
35-
super(context, attrs);
36-
initUI(context);
36+
this(context, attrs, 0);
3737
}
3838

3939
public TitleBar(Context context) {
40-
super(context);
41-
initUI(context);
40+
this(context, null, 0);
4241
}
4342

4443
private void initUI(Context ctx) {
4544
LayoutInflater.from(ctx).inflate(R.layout.layout_common_title_bar, this);
4645

47-
mLeftText = (TextView) findViewById(R.id.left_text);
48-
mRightText = (TextView) findViewById(R.id.right_text);
46+
mLeftBtn = (ImageView) findViewById(R.id.left_text);
47+
mRightBtn = (ImageView) findViewById(R.id.right_text);
4948
mTitleText = (TextView) findViewById(R.id.title_text);
5049
setStatusBarVisible(BaseActivity.getTopActivity().isStatusBarTranslate());
5150
}
@@ -67,14 +66,14 @@ private void setStatusBarVisible(boolean visible) {
6766
* @param l
6867
*/
6968
public void setLeftListener(OnClickListener l) {
70-
mLeftText.setOnClickListener(l);
69+
mLeftBtn.setOnClickListener(l);
7170
}
7271

7372
/**
7473
* 设置左边按钮的显示 默认是显示
7574
*/
7675
public void setLeftImageVisible(int visible) {
77-
mLeftText.setVisibility(visible);
76+
mLeftBtn.setVisibility(visible);
7877
}
7978

8079
/**
@@ -83,7 +82,7 @@ public void setLeftImageVisible(int visible) {
8382
* @param resourceID
8483
*/
8584
public void setLeftImageResource(int resourceID) {
86-
mLeftText.setBackgroundResource(resourceID);
85+
mLeftBtn.setImageResource(resourceID);
8786
}
8887

8988
/**
@@ -92,14 +91,14 @@ public void setLeftImageResource(int resourceID) {
9291
* @param l
9392
*/
9493
public void setRightListener(OnClickListener l) {
95-
mRightText.setOnClickListener(l);
94+
mRightBtn.setOnClickListener(l);
9695
}
9796

9897
/**
9998
* 设置左边按钮的显示 默认不显示
10099
*/
101100
public void setRightImageVisible(int visible) {
102-
mRightText.setVisibility(visible);
101+
mRightBtn.setVisibility(visible);
103102
}
104103

105104
/**
@@ -108,7 +107,7 @@ public void setRightImageVisible(int visible) {
108107
* @param resourceID
109108
*/
110109
public void setRightImageResource(int resourceID) {
111-
mRightText.setBackgroundResource(resourceID);
110+
mRightBtn.setImageResource(resourceID);
112111
}
113112

114113
/**
@@ -149,16 +148,16 @@ public void setTitleTextColor(int color) {
149148
*
150149
* @return
151150
*/
152-
public TextView getRightButton() {
153-
return mRightText;
151+
public ImageView getRightButton() {
152+
return mRightBtn;
154153
}
155154

156155
/**
157156
* 获取左边按钮
158157
*
159158
* @return
160159
*/
161-
public TextView getLeftButton() {
162-
return mLeftText;
160+
public ImageView getLeftButton() {
161+
return mLeftBtn;
163162
}
164163
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:color="#888888" >
4+
<item android:drawable="@drawable/bg_bloglist_item" />
5+
</ripple>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item android:drawable="@drawable/bg_bloglist_item" />
4+
</selector>

app/src/main/res/layout/activity_main_tab.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
android:layout_height="24dp"
4040
android:layout_alignParentRight="true"
4141
android:layout_centerVertical="true"
42-
android:background="@drawable/ic_search"
42+
android:src="@drawable/ic_search"
43+
android:background="?android:attr/selectableItemBackground"
4344
android:layout_marginRight="5dp" />
4445
</RelativeLayout>
4546

app/src/main/res/layout/activity_search.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
android:id="@+id/bt_search"
3737
android:layout_width="wrap_content"
3838
android:layout_height="wrap_content"
39+
android:background="?android:attr/selectableItemBackground"
3940
android:gravity="center"
4041
android:padding="5dp"
4142
android:textSize="18sp"

app/src/main/res/layout/item_list_blog.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
android:layout_width="match_parent"
44
android:layout_height="wrap_content"
5-
android:background="@drawable/bg_bloglist_item"
5+
android:background="@drawable/bg_item_bloglist_ripple"
66
android:orientation="vertical" >
7+
<!--bg_bloglist_item-->
78

89
<TextView
910
android:id="@+id/title"

app/src/main/res/layout/item_list_search.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
android:orientation="vertical"
6-
android:background="@drawable/bg_bloglist_item"
6+
android:background="@drawable/bg_item_bloglist_ripple"
77
android:paddingBottom="5dp"
88
android:paddingTop="5dp" >
99

app/src/main/res/layout/layout_common_title_bar.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
android:layout_height="@dimen/head_height">
1717

1818
<!-- 左侧按钮 -->
19-
<TextView
19+
<ImageView
2020
android:id="@+id/left_text"
2121
android:layout_width="24dp"
2222
android:layout_height="24dp"
2323
android:layout_alignParentLeft="true"
2424
android:layout_centerVertical="true"
2525
android:layout_marginLeft="3dp"
26-
android:background="@drawable/ic_back"
26+
android:src="@drawable/ic_back"
27+
android:background="?android:attr/selectableItemBackground"
2728
android:ellipsize="end"
2829
android:singleLine="true"
2930
android:textSize="16sp"
@@ -47,14 +48,15 @@
4748
android:textSize="20sp" />
4849

4950
<!-- 右侧按钮 -->
50-
<TextView
51+
<ImageView
5152
android:id="@+id/right_text"
5253
android:layout_width="24dp"
5354
android:layout_height="24dp"
5455
android:layout_alignParentRight="true"
5556
android:layout_centerVertical="true"
5657
android:layout_marginRight="5dp"
57-
android:background="@drawable/ic_share"
58+
android:src="@drawable/ic_share"
59+
android:background="?android:attr/selectableItemBackground"
5860
android:ellipsize="end"
5961
android:singleLine="true"
6062
android:textSize="16sp"

app/src/main/res/layout/person_center.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
<RelativeLayout
2626
android:id="@+id/chat"
27+
android:background="?android:attr/selectableItemBackground"
2728
android:layout_width="match_parent"
2829
android:layout_height="@dimen/user_center_menu_height" >
2930

@@ -56,6 +57,7 @@
5657

5758
<RelativeLayout
5859
android:id="@+id/news"
60+
android:background="?android:attr/selectableItemBackground"
5961
android:layout_width="match_parent"
6062
android:layout_height="@dimen/user_center_menu_height" >
6163

@@ -89,6 +91,7 @@
8991

9092
<RelativeLayout
9193
android:id="@+id/blog_favo"
94+
android:background="?android:attr/selectableItemBackground"
9295
android:layout_width="match_parent"
9396
android:layout_height="@dimen/user_center_menu_height" >
9497

@@ -122,6 +125,7 @@
122125

123126
<RelativeLayout
124127
android:id="@+id/blog_history"
128+
android:background="?android:attr/selectableItemBackground"
125129
android:layout_width="match_parent"
126130
android:layout_height="@dimen/user_center_menu_height" >
127131

@@ -155,6 +159,7 @@
155159

156160
<RelativeLayout
157161
android:id="@+id/select_article_type"
162+
android:background="?android:attr/selectableItemBackground"
158163
android:layout_width="match_parent"
159164
android:layout_height="@dimen/user_center_menu_height" >
160165

@@ -188,6 +193,7 @@
188193

189194
<RelativeLayout
190195
android:id="@+id/checkUpdateView"
196+
android:background="?android:attr/selectableItemBackground"
191197
android:layout_width="match_parent"
192198
android:layout_height="@dimen/user_center_menu_height" >
193199

@@ -221,6 +227,7 @@
221227

222228
<RelativeLayout
223229
android:id="@+id/aboutView"
230+
android:background="?android:attr/selectableItemBackground"
224231
android:layout_width="match_parent"
225232
android:layout_height="@dimen/user_center_menu_height" >
226233

@@ -254,6 +261,7 @@
254261

255262
<RelativeLayout
256263
android:id="@+id/settings"
264+
android:background="?android:attr/selectableItemBackground"
257265
android:layout_width="match_parent"
258266
android:layout_height="@dimen/user_center_menu_height" >
259267

0 commit comments

Comments
 (0)